Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,741,492 Members 39,548 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
no2chem
Old
(Last edited by no2chem; 13th January 2013 at 06:54 PM.)
#1  
Senior Member - OP
Thanks Meter 101
Posts: 275
Join Date: Jul 2007
Default [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

Visual Studio 2012 (Don't know if express will work, but evaluation editions exist here: http://www.microsoft.com/visualstudio/eng/downloads)

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

Part 1: Getting necessary libs:

(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).

(2) Create a directory on your development machine for the libs (we'll call it C:\rtdev\libs)

(3) Extract the dll-to-lib to your lib directory

(4) Open powershell (run powershell.exe) and navigate to the libs directory

(5) run the lib script against the dlls ("./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.

(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.

Part 2: Fixing the compiler.

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/1...al-studio-2012

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.

Now that we have the libs out of the way, lets build a basic hello world app.

(1) Start Visual Studio 2012.

(2) Create a new project, select Visual C++ (might be under other languages) and pick Win32 Project.

(3) In the wizard, select "Console Application", and press "Finish".

(4) Replace the program body with some text that prints 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".

(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.

Part 4: Porting Apps

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.

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.

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.

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/libr...(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.

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/1...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.

...hopefully this helps someone - happy coding!
The Following 15 Users Say Thank You to no2chem For This Useful Post: [ Click to Expand ]
 
lilstevie
Old
#2  
lilstevie's Avatar
Senior Recognized Developer
Thanks Meter 1021
Posts: 1,304
Join Date: Apr 2009

 
DONATE TO ME
Quote:
Originally Posted by no2chem View Post
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.
I have found with some nmake projects you need to add
Code:
Select Code
/D _ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE
to your CFLAGS otherwise cl complains about not being able to build desktop arm executables even with the change made to visual studio
The Following 2 Users Say Thank You to lilstevie For This Useful Post: [ Click to Expand ]
 
rheza02
Old
#3  
Senior Member
Thanks Meter 10
Posts: 459
Join Date: May 2006
Quote:
& : The term 'dumpbin.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At C:\rtdev\libs\dll-to-lib.ps1:62 char:25
+ $unprocesseddef = &$dumpbin /exports $dllfullpath
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (dumpbin.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Exception calling "Matches" with "1" argument(s): "Value cannot be null.
Parameter name: input"
At C:\rtdev\libs\dll-to-lib.ps1:65 char:5
+ $matches = [System.Text.RegularExpressions.MatchCollection] $regex.Matches($ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: ( [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
Thank you for the tutorial, i currently facing issues on step 5, it seems the script can't access the dumpbin.exe, any suggestion ?
oh, hello...
 
lilstevie
Old
#4  
lilstevie's Avatar
Senior Recognized Developer
Thanks Meter 1021
Posts: 1,304
Join Date: Apr 2009

 
DONATE TO ME
Quote:
Originally Posted by rheza02 View Post
Thank you for the tutorial, i currently facing issues on step 5, it seems the script can't access the dumpbin.exe, any suggestion ?
You should be running the script on your development machine with visual studio installed
The Following User Says Thank You to lilstevie For This Useful Post: [ Click to Expand ]
 
rheza02
Old
#5  
Senior Member
Thanks Meter 10
Posts: 459
Join Date: May 2006
Quote:
Originally Posted by lilstevie View Post
You should be running the script on your development machine with visual studio installed
i'm running it in my development machine with visual studio 2012 installed, Any idea ?
oh, hello...
 
no2chem
Old
#6  
Senior Member - OP
Thanks Meter 101
Posts: 275
Join Date: Jul 2007
[QUOTE=rheza02;36653941]i'm running it in my development machine with visual studio 2012 installed, Any idea ?[/QUOTE

Do you have VS2012 express? Possibly the script will not work if you don't have vs2012 express. Also you need to have $VS110COMNTOOLS set, but VS2012 install should set that for you.
The Following User Says Thank You to no2chem For This Useful Post: [ Click to Expand ]
 
GoodDayToDie
Old
#7  
Recognized Developer
Thanks Meter 2645
Posts: 5,550
Join Date: Jan 2011
Location: Seattle
To be more clear, you may want to try running the tool from the Visual Studio command line, not just bog-standard CMD (unless you want to set a bunch of environment variable sand such by hand). You should be able to invoke the script by typing powershell <scriptname>
Win8/Windows RT projects:
List of desktop apps for hacked RT devices

WP8 projects:
Native Access WebServer and Libraries
WP8 Interop Unlocks
Storage Cleanup tool

WP7 projects:
XapHandler, Root Webserver, OEM Marketplace XAPs, Bookmarklets collection (Find On Page), Interop-unlock hacks.


Do not private message me with questions that should have been posted on the forum! Not only are you wasting your time - I'm not going to bother writing an answer to such a question for only one person - but I will probably block you from PMing me in the future as well.
The Following User Says Thank You to GoodDayToDie For This Useful Post: [ Click to Expand ]
 
rheza02
Old
(Last edited by rheza02; 13th January 2013 at 01:00 PM.)
#8  
Senior Member
Thanks Meter 10
Posts: 459
Join Date: May 2006
Quote:
cmd.exe : The system cannot find the path specified.
This is the first error when i'm trying to run the script.
oh, hello...
 
no2chem
Old
#9  
Senior Member - OP
Thanks Meter 101
Posts: 275
Join Date: Jul 2007
Quote:
Originally Posted by rheza02 View Post
This is the first error when i'm trying to run the script.
looks like you don't have powershell installed. are you running an older version of windows? You can download it here http://www.microsoft.com/en-us/downl....aspx?id=34595
The Following User Says Thank You to no2chem For This Useful Post: [ Click to Expand ]
 
rheza02
Old
#10  
Senior Member
Thanks Meter 10
Posts: 459
Join Date: May 2006
I'm running windows 8, i can't see any value inside path in my environment variable, do you think it gonna be problem ?

oh, hello...

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes