Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

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

OP no2chem

13th January 2013, 05:51 AM   |  #1  
OP Senior Member
Thanks Meter: 101
 
275 posts
Join Date:Joined: Jul 2007
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!
Last edited by no2chem; 13th January 2013 at 07:54 PM.
The Following 15 Users Say Thank You to no2chem For This Useful Post: [ View ]
13th January 2013, 06:57 AM   |  #2  
lilstevie's Avatar
Senior Recognized Developer
Thanks Meter: 1,040
 
1,334 posts
Join Date:Joined: Apr 2009
Donate to Me
More
Quote:
Originally Posted by no2chem

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:
/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: [ View ]
13th January 2013, 11:41 AM   |  #3  
Senior Member
Thanks Meter: 10
 
459 posts
Join Date:Joined: 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 ?
13th January 2013, 11:48 AM   |  #4  
lilstevie's Avatar
Senior Recognized Developer
Thanks Meter: 1,040
 
1,334 posts
Join Date:Joined: Apr 2009
Donate to Me
More
Quote:
Originally Posted by rheza02

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: [ View ]
13th January 2013, 12:07 PM   |  #5  
Senior Member
Thanks Meter: 10
 
459 posts
Join Date:Joined: May 2006
Quote:
Originally Posted by lilstevie

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 ?
13th January 2013, 12:25 PM   |  #6  
OP Senior Member
Thanks Meter: 101
 
275 posts
Join Date:Joined: 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: [ View ]
13th January 2013, 12:53 PM   |  #7  
Recognized Developer
Flag Seattle
Thanks Meter: 2,791
 
5,877 posts
Join Date:Joined: Jan 2011
More
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>
The Following User Says Thank You to GoodDayToDie For This Useful Post: [ View ]
13th January 2013, 01:55 PM   |  #8  
Senior Member
Thanks Meter: 10
 
459 posts
Join Date:Joined: 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.
Last edited by rheza02; 13th January 2013 at 02:00 PM.
13th January 2013, 02:11 PM   |  #9  
OP Senior Member
Thanks Meter: 101
 
275 posts
Join Date:Joined: Jul 2007
Quote:
Originally Posted by rheza02

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: [ View ]
13th January 2013, 02:14 PM   |  #10  
Senior Member
Thanks Meter: 10
 
459 posts
Join Date:Joined: 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 ?


Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes