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

Search This thread

no2chem

Senior Member
Jul 18, 2007
276
102
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/showthread.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/11151474/can-arm-desktop-programs-be-built-using-visual-studio-2012

Basically, edit:
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\ARM\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/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.

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

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:

lilstevie

Senior Recognized Developer
Apr 17, 2009
1,339
1,040
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
 
  • Like
Reactions: rew06 and xsoliman3

rheza02

Senior Member
May 20, 2006
481
12
& : 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 ?
 

GoodDayToDie

Inactive Recognized Developer
Jan 20, 2011
6,066
2,932
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>
 
  • Like
Reactions: rheza02

rheza02

Senior Member
May 20, 2006
481
12
I'm running windows 8, i can't see any value inside path in my environment variable, do you think it gonna be problem ?

BrZeG.png
 

lilstevie

Senior Recognized Developer
Apr 17, 2009
1,339
1,040
I'm running windows 8, i can't see any value inside path in my environment variable, do you think it gonna be problem ?

BrZeG.png

PATH is under system variables not user variables, have you tried opening powershell from the start screen, and executing the script from within powershell directly?
 
  • Like
Reactions: rheza02

rheza02

Senior Member
May 20, 2006
481
12
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>

8AFOO.png


it's the same thing, i only have a lot of 1kb files with different name in my libs folder. any suggestion guys ?

Thanks


----------------------------

nvm, I thinks it's working now.
 
Last edited:

jtg007

Senior Member
Jul 8, 2012
76
18
(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.

I keep getting these 3 errors. What's happening?

Thanks...

Edit - the ARM subfolder of the project is empty, which I'm guessing it shouldn't be. How do we fix that?
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    46.9 KB · Views: 407
Last edited:

rheza02

Senior Member
May 20, 2006
481
12
How do i compile my visual studio project for arm ?, there is no arm option in my build configuration.
 

jtg007

Senior Member
Jul 8, 2012
76
18
Read the OP. You have to select "New" from the "Active solution platform" dropdown and ARM should appear...

Sent from my SCH-I535 using xda app-developers app
 

no2chem

Senior Member
Jul 18, 2007
276
102
I keep getting these 3 errors. What's happening?

Thanks...

Edit - the ARM subfolder of the project is empty, which I'm guessing it shouldn't be. How do we fix that?

Hm, did you overwrite any of the libs in your VS folder? That might be a problem.. hopefully you have a backup...
 

Top Liked Posts

  • There are no posts matching your filters.
  • 15
    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/showthread.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/11151474/can-arm-desktop-programs-be-built-using-visual-studio-2012

    Basically, edit:
    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\ARM\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/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.

    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

    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!
    6
    I figured out a way to support RT desktop compilation without modifying the compiler's Microsoft.Cpp.ARM.Common.props file, which is nice if you want to distribute your changes to others.

    Set up each of your Visual Studio projects to have an ARM target as usual, then close Visual Studio. For each .vcproj file of the solution, do the following:

    1. Open the .vcproj file in Notepad or a similar text editor.
    2. Find the <PropertyGroup> tag representing the Debug ARM target. An example:
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
    3. Inside that PropertyGroup, add this tag:
    <WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>
    4. Repeat for any other ARM targets you have (typically Release).

    That tag is the same as the one you can add to Microsoft.Cpp.ARM.Common.props, but without having to modify your Visual Studio installation. For the extra .lib files, you can always just put them in one of your project directories and add that directory to your library path for the project. Then no changes to Visual Studio 2012 will be required to compile your project.
    2
    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
    2
    Did you manage to run anything in 2017? Please reply even if you didn't

    You can only build with VS2012
    2
    Reposting here to keep all porting hints in the same thread.

    danesh110 found that beta version of Visual Studio 2012 (VS11) contained the ARM MFC library: http://forum.xda-developers.com/showpost.php?p=40988765&postcount=690
    VS11 beta contains both static and DLL MFC versions, both debug and retail. You can download it here: http://download.microsoft.com/downl...-40C9-A53C-E6322E2F033D/VS11_BETA_ULT_ENU.iso, install it, for example, into virtual machine and grab files from "C:\Program Files\Microsoft Visual Studio 11.0\VC\atlmfc\lib\arm" folder.

    It is better to use Microsoft-made MFC than my files - as my sources contain some stubs and hacks.
    I've compared the MFC sources from VS11 beta with the retail VS2012 - they are more complete in beta. Sources contain files missing from the retail build.