Home » Language IDEs » C / C++ IDE (CDT) » Managed Build project with cross compile SUCCESS
Managed Build project with cross compile SUCCESS [message #172640] |
Tue, 11 July 2006 20:04  |
Eclipse User |
|
|
|
Hi -
I've battled with this off and on for some time now, and finally have
been able to make it work.
I'm developing a medium-sized OpenGL project on linux. My primary
development system is x86_64 (though at home I'm on i686 machine). My
primary target is i686. OK, by "target" I mean where the application runs.
In the past, I've done my development and debugging on my fast fast fast
x86_64 machine. When its all set, I use an Ant build script to export
the project to tar files. I transferred those files to the target
machine and built them there. Time consuming, inconvenient, but it worked.
As a first attempt to cross compile on the x86_64 machine I set up a 32
bit chroot environment. That environment worked great, but I couldn't
get eclipse to use it. I tried executing the 'dchroot' command as a
pre-build step, but that didn't work -- apparently (obviously) eclipse
doesn't use a single shell to run the build toolchain.
If this were a standard make project (which it is not) I could have (I
think, I only realized this after I solved the problem another way) used
a script that runs commands inside the chroot environment. Then wrap the
'make' command in the 'do_chroot' command. Might have worked, possibly
without error parsing? Not sure, doesn't matter to me now.
I tried to use gcc's "-b" and "-V" options. These let you specify
another compiler version and target, and gcc forms a command name like
"i686-unknown-linux-gnu-g++" and calls it (provided its in your path).
Unfortunately gcc insists that "-b" be the first option on the command
line, and eclipse insists on making it later on the command line ( I
placed these options in the "Miscellaneous" section of the project
properties/C++ Build). No go. But I was close.
Finally, I hit upon the following solution. This isn't intended to be a
howto - if there's lots of interest I could turn it into one. I'm
writing this based on my notes from earlier today.......
1. Use crosstool. Visit www.kegel.com/crosstool . Nice tool, works great
(on my Ubuntu breezy machine, at least). All I needed to do was decide
on the gcc version I wanted, along with the glibc version. In my case it
was gcc 4.0.2 and glibc 2.3.6 (my target machines use Ubuntu dapper
6.06, and that's their flavor......er actually its gcc 4.0.3 but this
seems to be close enough). Anyways, read the quick start guide, set it
up, start it up and get a coffee. When you return you've got a full on
cross compiler and binutils. I used the default settings, so I ended up
with a folder called
/opt/crosstool/gcc-4.0.2-glibc-2.3.6/i686-unknown-linux-gnu/ bin/, and in
that folder were the following tools (the folder structure is more
complicated than I'm letting on here, and if I understood it completely
I'd explain. For now, this will suffice)
i686-unknown-linux-gnu-gcc
i686-unknown-linux-gnu-g++
i686-unknown-linux-gnu-ld
i686-unknown-linux-gnu-as
......
There is also a full set of clibs in
/opt/crosstool/gcc-4.0.2-glibc-2.3.6/i686-unknown-linux-gnu/ i686-unknown-linux-gnu/lib
and all the headers in (same/same/same/same/include). Furthermore, these
folders are where the crosstools look for their "standard" stuff (i.e.
where your regular gcc uses /usr/lib and /usr/include, the cross tools
use these folders).
2. In eclipse I created a new configuration within the project called
"i686". I actually have three separate projects, a shared c++ lib, a
static C lib, and a c++ executable which uses those two libs. In each
project, this involves opening the properties, select "C/C++ Build", and
change the "command" for whatever tools are appropriate for the project.
In my shared C++ lib, for example, I changed the command for the C++
compiler to "i686-unknown-linux-gnu-g++". Similarly I changed the linker
command to the same. In the C lib project I changed the "C Compiler"
command to "i686-unknown-linux-gnu-gcc".
3. Still in the project properties, select the Environment tab. Hit
"New" and enter "PATH" for the name. The current value of your path var
appears. Prepend this with the path to the bin folder that contains your
crosstools.
Make certain you are doing this in the "Configuration" tab, not the
"Project" tab! You only want this path change for the cross-compiling
configuration.
[ Note: I noticed after the fact that the crosstools exist in another
folder with the "ordinary" names of gcc, g++, etc. I could have used
those names and adjusted the PATH variable accordingly. YMMV. ]
4. At this point eclipse should call the correct compiler, but likely
you'll get lots of errors. If your project, like mine, requires lots of
stuff from outside the base /usr/include stuff, then you need to acquire
the appropriate libraries for the target platform (along with the
headers). In my case, the fact that I had already set up a chroot'd
environment came in handy as all the libs were there already. Under
Ubuntu (probably with Debian as well) I found it easy to install the
chroot env libraries using apt-get. There's some HOWTO's out there for
setting up the chroot under Ubuntu and configuring it to allow use of
apt-get or synaptic.
I copied the libs I needed to the crosstool lib/ folder, and the include
files to the crosstool include/ folder. In some cases I used softlinks.
No rhyme or reason - that's just what I did. Had to mess with some other
env variables I set for the project - that's simple because eclipse
allows for per-configuration env variable settings. Nice.
After all this was said and done I can select the "i686" build
configuration and build my project for the target platform. I move the
binaries to the target and (drumroll.....) they work!
I hope this helps some folks out there. Like I said, I'd be glad to turn
this into a more complete howto if there's interest.
Happy cross-compiling!
Dan
|
|
| |
Re: Managed Build project with cross compile SUCCESS [message #172717 is a reply to message #172664] |
Wed, 12 July 2006 14:03  |
Eclipse User |
|
|
|
> I'm thinking about using the "managed project" features of Eclipse. Will
> same automatically build the Makefile(s) in a way that the dependencies
> between the source and header files are acknowledged (my final project
> will have some 100 source files) ?
>
Managed make generates dependency files for all your source files, so in
principle the answer is "yes". Modify a header and those files which
#include it are rebuilt.
Good luck - let me know how it goes!
dAn
|
|
|
Goto Forum:
Current Time: Thu Sep 18 18:45:20 EDT 2025
Powered by FUDForum. Page generated in 0.02949 seconds
|