win32アプリをwindows RT用に再コンパイルする方法

xda-developers
[how to] compile and port win32 apps to Windows RT ARM


Here's a basic guide on how to port, since some people were asking:


どうやって移植できるかの基本的なガイド。何人かに聞かれたので

Prerequisites:
準備

Windows 8 (non-RT) development machine
window 8開発マシン(RTじゃない)

Visual Studio 2012 (Don't know if express will work, but evaluation editions exist here: http://www.microsoft.com/visualstudio/eng/downloads)
Visual Studio 2012
Visual studio 2012 (元記事コメントからだとexpressではだめらしい)

dll-to-lib tool (http://forum.xda-developers.com/show...php?p=36597774)


Part 1: Getting necessary libs:
パート1: 必要なライブラリの準備

(1) On your Windows RT device, copy the .dll files in C:\Windows\System32 to some directory on your development machine (We'll call it C:\rtdev\dlls).
(1)Windows RTデバイス上で、C:\Windows\System32\*.dllファイルを(USBメモリ等に)コピーする

(2) Create a directory on your development machine for the libs (we'll call it C:\rtdev\libs)
(2)開発マシンにC:\rtdev\libsディレクトリを作成する。以下libディレクトリと呼ぶ。
(書いてないけど、(1)でコピーした.dllをペーストする)
 (C:\rtdev\dllsは任意でいいらしいがこのディレクトリだったとして以下説明を続ける)

(3) Extract the dll-to-lib to your lib directory
(3)dll-to-lib toolをlibディレクトリで展開する

(4) Open powershell (run powershell.exe) and navigate to the libs directory
(4)powershellを開き、libディレクトリに移動する

(5) run the lib script against the dlls ("./dll-to-lib.ps1 C:\rtdev\dlls).
(5)dllに対してdll-to-libを実行する"./dll-to-lib.ps1 C:\rtdev\dlls"

(6) If you've never run a powershell script before, you might get a signing error. You can type "Set-ExecutionPolicy Unrestricted" to run the script. Please be aware of the security implications if you choose to do this.
(6)もしpowershellスクリプトを実行したことが無い場合、サインエラーになるかもしれない。
 その時は"Set-ExecutionPolicy Unrestricted"と入力する。
 当然、これでセキュリティの問題が起こっても自己責任である。

(7) You now have a bunch of libs that tell the linker what functions are available in the DLLs on the Windows RT device. Copy the libs that you need to "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\arm". DO NOT OVERWRITE ANY EXISITNG LIBS (repeat: DO NOT OVERWRITE ANY EXISITNG LIBS OR YOU MAY HAVE TO REPAIR/REINSTALL VS) You'll probably have to change the security permissions if you want to copy to this directory, or copy as an administrator. 
 (7)これでいくつかのwindows RT用dllのファンクションがライブラリとしてリンクされた。
 libを"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\arm"にコピーするが、絶対に上書きコピーをしてはいけない。
 もしかすると、このディレクトリにコピーするためにはセキュリティパーミッションを変更する必要があるかもしれない。もしくは管理者権限ユーザーでやってね。


Part 2: Fixing the compiler.
パート2:コンパイラ修正

The compiler won't let you build desktop apps due to a configuration setting. Fortunately, some people at stack overflow figured this out: 
http://stackoverflow.com/questions/11151474/can-arm-desktop-programs-be-built-using-visual-studio-2012
このコンパイラは設定でデスクトップアプリをビルド出来ないようになっている。
しかし幸いなことに、stack overflowに解決策がある。

Basically, edit:
基本以下を編集して
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\AR M\Microsoft.Cpp.ARM.Common.props


to include:
以下を追加する
<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>
before </PropertyGroup>


Part 3: Building a Win32 Hello World app.
パート3:Hello World

Now that we have the libs out of the way, lets build a basic hello world app. 
準備ができたので、基本的なHello worldアプリをビルドしてみよう。

(1) Start Visual Studio 2012.
(1)Visual Studio 2012をスタート

(2) Create a new project, select Visual C++ (might be under other languages) and pick Win32 Project.
(2)新プロジェクト-Visual C++(他の言語でもよい)-Win32プロジェクトを選択

(3) In the wizard, select "Console Application", and press "Finish".
(3)ウィザードで "Console Application"を選択して"Finish"

(4) Replace the program body with some text that prints hello world:
(4)プログラム本体をhello world用に編集

#include "stdafx.h"
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
printf("Hello World!");
return 0;
}

(5) Add the ARM configuration settings in configuration manager. Goto Build>Configuration Manager, and under "Active Solution Platform" click on Win32 and click New. Select "ARM" under "Type or select the new platform", and press "OK".
(5)ARM設定をconfiguration managerで追加する。
 Build>Configuration Managerに行き、 "Active Solution Platform" のWin32をクリック。Newをクリック。
 "Type or select the new platform"の"ARM"を選択。"OK"

(6) Select the "Release" configuration and build the solution (F6). With some luck, some win32 ARM binaries should appear in the ARM subdirectory of your project.
(6)"Release"設定を選択し、ビルド(F6)。
 これでいくつかのwin32 ARMバイナリ
 (win32とARMどちらでも動くアプリという意味らしい)
 がプロジェクトのARMディレクトリ内にできているはずだ。

Part 4: Porting Apps
パート4:アプリの移植

Now that your compiler works, you can port apps over. Most apps that have a VC++ project should port fine just by adding the ARM configuration. 
コンパイラが動いたところで、アプリの移植が可能になる。
VC++で書かれている多くのアプリはARM設定を追加しても大抵動くようだ。

Some apps will have manually set \MACHINE:x86, in which case you will have to change that in the linker options. Also, ARM doesn't support no dynamic rebase, so if you get that error, turn of \DYNAMICBASE:NO in the linker options.
いくつかのアプリはきっちりと \MACHINE:x86になっているが、
この場合はリンカオプションを変更する。
また、ARMはdynamic rebaseをサポートしていないので、
エラーが出た場合はリンカオプションで\DYNAMICBASE:NOとする。

A lot of cross-platform apps will use 'nmake' or the like. For the most part, these apps can be cross compiled using the VS 2012 ARM Cross Tools - you can find that in your start menu- In Windows 8 just type "ARM" and it should show up.
多くのクロスプラットフォームアプリが'nmake'やそのようなものを使っている。
多くの場合、このようなアプリはVS 2012 ARM Cross Toolsを使ってクロスコンパイルが可能となる。
これはWindows8のスタートメニューで"ARM"と入力すると出てくる。


Also some interesting issues might experience:
その他面白いはなし

You might encounter missing symbols from __imp_XXXX or the like from the linker. If it looks like a Win32 function, you just need to explicitly add the .lib (in project properties under Linker->Input->Additional Dependencies, type the name of the lib, which you need to also copy to the VC\lib\arm directory as above. Some common libs include "gdi32.lib" "shell32.lib" and "ole32.lib". You can usually find the .lib under the msdn references: for example this entry for GetUserName http://msdn.microsoft.com/en-us/library/windows/desktop/ms724432(v=vs.85).aspx tells us we can find GetUserName in Advapi32.lib. Also the A and W suffixes just represent the ANSI and unicode version of these functions.
もし __imp_XXXXシンボルが見つからないとか、リンカで同様のことが起きたら。
Win32ファンクションを見て、.libを追加する必要がある。
(プロジェクトプロパティ>Linker->Input->Additional Dependencies。
libの名前を入力し、上記VC\lib\armディレクトリにもコピーする。
例えばいくつかの一般的なlibは"gdi32.lib" "shell32.lib" "ole32.lib"をincludeしている。
.libはmsdnリファレンスで普通見つけることができる。
例としてGetUserNameエントリ
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724432(v=vs.85).aspx
はAdvapi32.lib中にGetUserNameを見つけられることを教えてくれる。
またAとWサフィックスがこのファンクションのANSIとUNICODEバージョンとして表示される。

When compiling big libraries like Qt, you might run into some problem about BLX fixups, since relative jumps on arm are limited (23 bits?) I guess they didn't create fixup islands in the MSVC compiler, but I found if you set \INCREMENTAL:NO, that should fix the problem most of the time. Otherwise you might have to add an \ORDER file and manually order things. See stack overflow topic for more details: http://stackoverflow.com/questions/11478055/lnk2013-error-fixup-overflow
もしQtのような巨大なライブラリをコンパイルする場合、
BLX fixups関連の問題にぶつかるかもしれない。
armのrelative jumpは制限されているからだ(23bit?)
彼ら(Qt)はMSVCコンパイラ用に特別な処置はしないだろうけど、
\INCREMENTAL:NOとすると大抵大丈夫なことを発見した。
あるいは、\ORDERファイルを手動で追加すべきかもしれない。
詳細はstack overflowの以下トピックを見て欲しい。
http://stackoverflow.com/questions/11478055/lnk2013-error-fixup-overflow

Another serious pitfall.. no in-line assembly support in the MS ARM compiler. So you'll have to write in your assembly in a .S file and link to it.
他の問題は...MS ARMコンパイラはインラインアセンブリをサポートしていないことが。
だからアセンブリを.Sファイルに書き、リンクしなければいけないかもだ。

...hopefully this helps someone - happy coding!
誰かの助けになればいいな。happy coding!

Comments

Popular posts from this blog

MacbookやiMacのSSD/HDDを完全消去する(High Sierra対応版)

conda clean --allはやってはいけない

Nintendo SwitchがあればChromecastはいらないぞ!