? Compiling With Gcc 4.x


MSweeney

Still Fresh
Joined
Mar 20, 2006
Messages
38
Age
49
Location
Washington, USA (but I still love you)
Website
Visit site
Hello, might need to be moved to 'I need help', but I thought it was maybe a general question so could also live here. Mods please move as see fit.

Basically, I am looking for info concerning Compiling for FW 2.0 on GCC 4.x. As I have mentioned before, I am not very experienced with the Linux development tools so these questions may have simple answers that seem obvious to some ;)

1. If I compile using GCC 4.x, how does this impact the C/C++ libraries (assuming I use any). For example, I assume I can statically link the libs in - so that may not be a problem... but what about calling into Firmware, or other system calls. I imagine that straight ASM Software Int calls should be no problem so long as the correct registers are set.

2. If I do want to use dynamic libs, can I include those with my 'exe' and then how do I make sure it uses those and not any others that may be present in the system. Please be aware I am familiar with windows and DLL's so it may be totally different than I think in actuality - but I assume at least the concept of dynamic/static libs is the same regardless of how they are loaded.

3. I am developing on Windows, and currently using the windows compiled versions of arm-linux-gcc etc. I didn't even check the versions, but I grabbed the distro from here and I'm pretty sure it does NOT use GCC 4.x. So, I want to make Windows versions of those executables, is that a fairly simple process? For example, can I actually compile the GCC 4.x toolchain using the Windows versions of an older GCC toolchain? (if you follow my reasoning). I do have a Linux box, and a Linux Virtual Server, so I suppose I could cross-compile to Windows if need be. Obviously I would prefer to just download them =)

4. How does using GCC 4.x toolchain effect SDL with the GP2x? I would like to use the Accelerated version of SDL - I assume I can simply get the source and compile... Please correct and slap me around a bit if I am making no sense.

Anyway thanks again for fielding my long and often stupid questions, this Forum has been a great help so far - and I plan to give back and write up a guide for Windows GP2X developers who are not familiar with Linux in the near future.

Matt

:blink:
 
(Moving to the "Place where really smart people go to discuss coding stuff")
 
MSweeney posted on May 3 2006 at 10:37 PM said:
1. If I compile using GCC 4.x, how does this impact the C/C++ libraries (assuming I use any). For example, I assume I can statically link the libs in - so that may not be a problem... but what about calling into Firmware, or other system calls. I imagine that straight ASM Software Int calls should be no problem so long as the correct registers are set.
While it is possible to build stuff to use the .so files that are already installed, using GCC 4 means that it's much easier to statically link against .a files. This results in an executable that's larger than you may prefer, but at least it works. Calling directly to firmware is, of course, external to any libraries and/or versions, so that should all work fine.

2. If I do want to use dynamic libs, can I include those with my 'exe' and then how do I make sure it uses those and not any others that may be present in the system. Please be aware I am familiar with windows and DLL's so it may be totally different than I think in actuality - but I assume at least the concept of dynamic/static libs is the same regardless of how they are loaded.
You can create your own libs and/or use prebuilt shared libs. To include these in your executable, you simply point to them by setting the environment variable LD_LIBRARY_PATH to the list of directories in which the system should look for dynamic libs. This is a difference from Windows: PATH points to pure executables, but LD_LIBRARY_PATH points to the dynamic libs, which on Windows is included in PATH.

3. I am developing on Windows, and currently using the windows compiled versions of arm-linux-gcc etc. I didn't even check the versions, but I grabbed the distro from here and I'm pretty sure it does NOT use GCC 4.x. So, I want to make Windows versions of those executables, is that a fairly simple process? For example, can I actually compile the GCC 4.x toolchain using the Windows versions of an older GCC toolchain? (if you follow my reasoning). I do have a Linux box, and a Linux Virtual Server, so I suppose I could cross-compile to Windows if need be. Obviously I would prefer to just download them =)
You can download & install the latest versions of the toolchain. I'm a little confused as to why you're so focused on v4.0 - I just checked and the version I'm using is 3.4.4 (in Cygwin), and I'm quite happy with that. There is a script that automatically downloads all the files and builds the toolchain. I ran this on Linux & it worked fine: I'm pretty sure it wouldn't be too difficult to take these downloaded sources & build them on cygwin.

4. How does using GCC 4.x toolchain effect SDL with the GP2x? I would like to use the Accelerated version of SDL - I assume I can simply get the source and compile... Please correct and slap me around a bit if I am making no sense.
No idea - haven't used SDL.
 
Last edited by a moderator:
Hi,
MSweeney posted on May 3 2006 at 10:37 PM said:
1. If I compile using GCC 4.x, how does this impact the C/C++ libraries (assuming I use any). For example, I assume I can statically link the libs in - so that may not be a problem... but what about calling into Firmware, or other system calls. I imagine that straight ASM Software Int calls should be no problem so long as the correct registers are set.
At the moment, static linking is the easiest option, if you don't mind the size of the resulting binaries. The version of GCC seems to have no impact on the low-level stuff like syscalls (there's an interesting discussion of this in one of the recent demo programming topics.)

MSweeney posted on May 3 2006 at 10:37 PM said:
2. If I do want to use dynamic libs, can I include those with my 'exe' and then how do I make sure it uses those and not any others that may be present in the system. Please be aware I am familiar with windows and DLL's so it may be totally different than I think in actuality - but I assume at least the concept of dynamic/static libs is the same regardless of how they are loaded.
There are a couple of ways to do this. The proper way is to copy your libs into /lib or /usr/lib. update the symbolic links if necessary and run ldconfig to update the cache and links. However, the GP2X doesn't have ldconfig installed by default, and there is the possibility that copying new libs over to your NAND on a regular basis runs the risk of weariing it out.

Another way is to set an environment variable called LD_LIBRARY_PATH which is like the normal search path, but the system will look in the listed locations first, before going to the locations listed in /etc/ld.so.conf.

The third way is to set an environment variable on your developement system when linking, called LD_RUN_PATH. This path will be hard-coded into the exectuable, and will be searched for libraries before any other location. So you could put updated libs in this location. I use /mnt/sd/lib myself.

However, there is a small problem that I've run into and that is that the dynamic linker (ld-linux) on the GP2X is version 2.2.5, and the version on my dev system is 2.3.5, and there is a conflict there. So, to launch your binary you have to explicitly use the new dynamic linker to launch your executable, e.g. "/mnt/sd/lib/ld-2.3.5.so ./mybinary", otherwise the system seems to use the resident linker, which is of course the older version, and won't be acceptable to the new versions of glibc etc. It's worth reading up on the documentation for ld-linux, as you can use it as a diagnostic tool to resolve library dependencies.

A workaround could be to link against the older versions of the libraries, but I haven't had a chance to try this yet, so I can't say for any certainty if it will work, or if you need to have a whole other toolchain set up.

MSweeney posted on May 3 2006 at 10:37 PM said:
3. I am developing on Windows, and currently using the windows compiled versions of arm-linux-gcc etc. I didn't even check the versions, but I grabbed the distro from here and I'm pretty sure it does NOT use GCC 4.x. So, I want to make Windows versions of those executables, is that a fairly simple process? For example, can I actually compile the GCC 4.x toolchain using the Windows versions of an older GCC toolchain? (if you follow my reasoning). I do have a Linux box, and a Linux Virtual Server, so I suppose I could cross-compile to Windows if need be. Obviously I would prefer to just download them =)
'arm-linux-gcc -v" on my setup returns 4.0.2. In theory, you should be able to compile windows binaries without too much trouble, there seem to be quite a few people here doing just that, but I'm afraid I can't offer any opinions on that, as I'm also using the hardware directly, which makes a windows binary impractical.

An interesting thing I would like to bring to your attention is that just because you don't have a binary specifically for the GP2X, it doesn't mean you have to build it from source. I've had a lot of luck using console tools compiled for the Zaurus, and once they've been unpackaged and copied to the GP2X they run fine.
 
Last edited by a moderator:
Great thanks for the tips, I think I should be fine going ahead with Static Libs once I can get a version of GCC 4.x working under windows. Im not using Cygwin, I use the MinSys binaries currently. I guess I could switch to Linux, but I am developing under Visual Studio 2005 and targte both GP2X and Windows and I need to keep it that way for now (I compile both versions, because some of my 'testers' do not have a device).

That is also why I am kinda stuck on SDL, although I do intend to hit the hardware directly for the GP2X, and then provide DirectX support for the Windows version.

Cheers,

Matt
 
Back
Top