Getting Cross-Compiling Up And Running On Windows


jdbye

Member
Joined
Dec 27, 2007
Messages
242
I checked the wiki and it looks like I need CodeSourcery but other than that there's very little info on what I need to do to get a IDE and toolchain running on Windows (with a build command from within the IDE). Though I don't NEED a IDE, I prefer having autocompletion etc. I wish there was a simple package with IDE, toolchain and SDL headers that I could just unzip and run like there was with GP2X. I'm slightly demotivated by the lack of info on how to do things :p

Did anyone write a guide already, or is there a better source of information than the wiki? I'm not used to cross-compiling, I've only done it on the NDS (and played around a bit on the GP2X) but that was pretty simple with devKitPro, since the setup took care of almost everything for me. I'm downloading CodeSourcery arm-2009q3 right now, that's about as much as the wiki told me to do. What else do I need?
 
Jdbye, I have cross compiling working for Windows, I am actually going on holiday from tomorrow for 11 days, and I was going to write a tutorial when I return about how to do it, but I'll see if I can find 30 minutes tonight to put together enough information on this thread to get you going.

Steve
 
Right, very quick bunch of information to get up and running!

1. Download and install arm-2010q1-202-arm-none-linux-gnueabi.exe - it's important to get this one and not arm-2010q1-188-arm-none-eabi.exe otherwise you'll be missing a bunch of functionality (for example dirent.h/utime.h) as this functionality is provided by the Linux layer.

You can then compile/link with:

Code:
Make libraries from objects : arm-none-linux-gnueabi-ar.exe ru
Compile C code              : arm-none-linux-gnueabi-g++.exe
Compile C++ code	    : arm-none-linux-gnueabi-g++.exe
Link an application	    : arm-none-linux-gnueabi-g++.exe
Index a library		    : arm-none-linux-gnueabi-ranlib.exe

They all live in:

Code:
C:\Program Files (x86)\CodeSourcery\Sourcery G++ Lite\bin

If you used the default install options.


2. I haven't got around to finding out what the best CFLAGS/LDFLAGS are to use yet, but the ones I have for now (that at least produce an executable I can run) are:

CFLAGS

Code:
-fsigned-char 	
-march=armv7-a 
-mtune=cortex-a8 
-mfpu=neon 
-mfloat-abi=softfp
-Wno-deprecated
-Wno-psabi

CFLAGS DEBUG (additional)

Code:
-g
-O0

CFLAGS RELEASE (additional)

Code:
-fomit-frame-pointer 
-O3

C++FLAGS - assumes you don't want RTTI or exceptions

Code:
-fno-exceptions
-fno-rtti

DEFINES

Code:
__ARM_ARCH_5__ 
__ARM_ARCH_5T__ 
__ARM_ARCH_5E__ 
__ARM_ARCH_5TE__ 
__NEW__ 
__SGI_STL_INTERNAL_PAIR_H 
_PANDORA
TCHAR=char

LDFLAGS - these don't completely make sense, I just copied them from Android for now - they at least work!

Code:
-Wl,--whole-archive 
-Wl,--no-whole-archive
-Wl,--no-undefined
-g
-lstdc++
-lrt
-Wl,-rpath=libs

You can note that the -Wl,-rpath=libs means at runtime, it'll look for any shared/dynamic libraries in a libs folder, more about this later...

3. Libraries - a couple of libraries I compiled myself (OpenAL/ALUT), but in general, most libraries are already available. I do not know too much about Linux, so there might be a better way to do this, but the thing I found is, if you download this:

20100611-i686-linux-armv7a-linux-gnueabi-toolchain-openpandora.tar.bz2

And then extract it somewhere (I used 7zip), you should end up with a bunch of files/directories, with the top one being 'usr'. You'll find a bunch of 'useful' headers in this subdirectory:

Code:
usr\local\angstrom\arm\arm-angstrom-linux-gnueabi\usr\include

And the corresponding libraries:

Code:
usr\local\angstrom\arm\arm-angstrom-linux-gnueabi\usr\lib

It's up to you what you do with this lot, but personally I decided to copy what I needed into a separate directory, for example, you could copy them into:

Code:
c:\pandorasdk

So you end up with:

Code:
c:\pandorasdk\include
c:\pandorasdk\lib

Then you can compile/link against this by adding to your flags:

Code:
CFLAGS += -Ic:/pandorasdk/include
LDFLAGS += -Wl,-rpath=c:/pandorasdk/lib -Lc:/pandorasdk/lib

I found both -rpath and -L were necessary. That should allow you to #include what you like, and allow you to link to a library by adding to your LDFLAGS like:

Code:
LDFLAGS += -lopenal -lGLES_CM -lx11

There is one additional thing you need to do (someone else might be able to suggest a way to skip this step), but I found it often tried to link to against a library which is 0 bytes in size, for example if we look at the GLES library, we have:

Code:
000,000 bytes - libGLES_CM.so
000,000 bytes - libGLES_CM.so.1
000,000 bytes - libGLES_CM.so.1.4
563,796 bytes - libGLES_CM.so.1.4.14.2514

I think essentially on Linux the first three would be a symlink to the last one, but on Windows this didn't work. So I just duplicated the last file three times, and renamed it to match the first free entries. I've repeated this for each library I have linked against. Maybe this sounds bonkers, but I have my complete game running now, and I think I only link against three libraries (x11/openal/GLES_CM) so I only had to copy/rename less than 10 files).

4. Once I had built my application, I copied it into a directory on an SD card, and created a libs folder along side, in this folder I put in any shared libraries I used (OpenAL/GLES/x11), one way to find out what libraries you need is not to include any, and just try running your application form the console window, it'll tell you what libraries are required, and you can just keep copying them in until you have everything. I'm sure there is a better way to do this, but I found I could do this in a minute or two and be all good to go.

5. Profit!

I hope that at least gives you a push in the right direction; as I say, I had planned on doing a more detailed tutorial after my holiday, but I thought I better just throw something quick together now to get you going. I should also mention I am using the JamPlus build system, it generates a Visual Studio workspace and lets you build from there, it is all very slick. JamPlus doesn't ship with Pandora support, but I've added support for Pandora, which I will be submitting to get included in the next release. So you may potentially want to check out JamPlus, it's up to you.

If anything doesn't make sense, I'm sure some of the brains on the forum will be able to help you out, and correct my crazy guide above!

Steve
 
Not to hijack this thread but...

After downloading and installing arm-2010q1-202-arm-none-linux-gnueabi.exe I get completely lost I use Code::Blocks 10.5 and I have no idea on where to enter any of the information you've given us.
 
Kordman916 said:
Not to hijack this thread but...

After downloading and installing arm-2010q1-202-arm-none-linux-gnueabi.exe I get completely lost I use Code::Blocks 10.5 and I have no idea on where to enter any of the information you've given us.

Sorry, the thread assumes some knowledge about how to build with a compiler, set up include directories, and so on and so forth. I don't really know much/anything about Code::Blocks, hopefully someone else on the forum will be able to point you in the right direction. I'm pretty sure in Code::Blocks it is possible to point it at a compiler, and specifying some compile/link flags, so hopefully you'll be able to get it up and running.

Steve
 
Last edited by a moderator:
I have minimal knowledge about compilers and such but I'm just having trouble setting it up in code::blocks maybe one of the other guys around here can point me in the right direction.
 
I know nothing about makefiles, but I should be able to figure it out with trial and error, and you even explained how to get the headers/libs, one thing I was wondering about :)
I also liked the way it looks for the libs at runtime.
I have a week to figure it out before my Pandora arrives, so I should be able to get it working by that time. Optimally, I want to be able to build Windows and Pandora targets from the same IDE, and have a template project that generates a makefile for me, but I'm not sure how to do that. Code::Blocks looks good though, will try to use that.
 
Have a Google for 'Code::Blocks "cross compiler"'. I think with what you find there and Rockthesmurf's parameters you should be well on your way.

I've done some Pandora work on Windows but I'm not into IDEs. A decent editor, MSYS and some of the MinGW tools were enough to get me going.
 
No idea if this might be helpful. It's a guide a wrote to set up a Code::Blocks to cross-compile in Linux.

http://www.gp32x.de/board/index.php?/topic/55075-setting-up-codeblocks-to-cross-compile-in-ubuntu/page__p__888030&#entry888030
 
Last edited by a moderator:
Just to add a quick note:
I've downloaded/installed the Sourcery package and added it to a new compiler profile in Dev-Cpp, just like I was using for the GP2X. Worked like a charm for a simple terminal program (helloWorld-like).

I haven't tested a real, graphical application (with GLES and all)
 
Back
Top