GNU C/C++ Cross Compiler + Eclipse Development Environment


43 posts   Page 1 of 2   1, 2
by halhertani » Fri Sep 28, 2012 9:42 pm
I've recently posted a tutorial on how to setup a Development environment on a Linux box/virtual machine that utilizes Eclipse and the cross Compiling toolchain (official one posted on github) to develop code for the Raspberry Pi.

http://hertaville.com/2012/09/28/development-environment-raspberry-pi-cross-compiler/

I hope others find it useful. All feedback is welcome
Posts: 40
Joined: Sun Aug 19, 2012 5:02 am
Location: Ottawa, ON Canada
by mapi » Sat Oct 20, 2012 8:48 pm
Exactly what I was looking for... thx!
Posts: 1
Joined: Sat Oct 20, 2012 8:39 pm
by Embed » Mon Oct 22, 2012 8:45 pm
What I don't understand is the "Cross GCC" option in Eclipse. I would think this is for quick selection to compile for another platform (in this case ARM) or for the local Linux installation - seem I am wrong. In your example, "Cross GCC" is not used, but instead "Linux GCC" for compiling to the ARM architecture.
Is there an easy one-click way to compile either for Intel or for ARM? Typical would be to develop and test on on Intel but sometimes switch to ARM to test on the target. Best would be separate directories for the output of the two different compilers/linkers.
Posts: 3
Joined: Sat Oct 20, 2012 10:52 am
by halhertani » Wed Oct 24, 2012 11:10 am
Embed,
I'm no expert on this myself, but I typically use the "Cross GCC" option when I program microcontrollers or barebone (no Linux) microprocessors (ARM or other non intel CPUs). I use the "Linux GCC" option whenever I intend to compile code that will run in Linux regardless of that machine's architecture.

I'm not sure if the "Cross GCC" option will work in our case... it very well might. One can also create a makefile based project and write their own makefiles to assert complete control over the build process
Posts: 40
Joined: Sun Aug 19, 2012 5:02 am
Location: Ottawa, ON Canada
by macca » Thu Oct 25, 2012 8:22 am
Hi,

I just followed your tutorial to setup Eclipse but it didn't work, the C/C++ project doesn't have the includes and library paths set. That's something I don't understand of your tutorial, how Eclipse knows the paths for the cross compiler ?

Then I have created a new project this time with the Cross GCC toolchain, entered the cross compiler prefix (in that case arm-linux-gnueabihf- with the traling dash) and the compiler path $HOME/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian and it worked, all paths are set correctly. I have just compiled the HelloWorld example, I don't know if there are other things missing.

I'm using Fedora 14 and Eclipse 4.2.1.
Posts: 31
Joined: Tue Oct 16, 2012 9:14 am
by halhertani » Thu Oct 25, 2012 12:19 pm
macca,
If you're using 64-bit version of linux you will need to install the ia32-libs (32-bit header/lib files) you may need to install the "linux headers" (32/64-bits) package as well since these are not included in the default fedora build.

In my tutorial I go through how one can include lib and include directories into the eclipse project (figures 10 & 11)
Posts: 40
Joined: Sun Aug 19, 2012 5:02 am
Location: Ottawa, ON Canada
by macca » Thu Oct 25, 2012 2:53 pm
Yes, I'm using 64-bit Fedora, all the libraries for 32-bit compatibility are installed, the cross compiler works, it is just the Eclipse configuration that doesn't work. Maybe I have not understood the paths section of the tutorial, I had the impression that the paths were added automatically by Eclipse not that one should enter all paths manually. And there aren't just the paths but also the executable names, and don't know what, very difficult to do for each project. If that's how it should be setup, then the Cross GCC option works better because it can figure out everything by itself.
Posts: 31
Joined: Tue Oct 16, 2012 9:14 am
by halhertani » Thu Oct 25, 2012 9:58 pm
Macca,
Yes the tutorial demonstrates which lib and include directories one has to add to the project manually, The paths to be added are shown figure 10 and 11 (about 5 paths for libs and 5 for includes).

I really doubt that the Cross GCC option is in any way superior to the Linux GCC option. But I will check. If you want to really automate the build process for the project, create a makefile project and modify the makefile as your heart desires....
Posts: 40
Joined: Sun Aug 19, 2012 5:02 am
Location: Ottawa, ON Canada
by shobley » Fri Oct 26, 2012 11:17 am
Hi,

I followed your guide and it worked OK in a VM, but Eclipse seems to be having problems highlighting bugs - specifically not finding iostream, std and cout. The executable builds fine. Is there another setting I need to adjust in the IDE?

Pictures here :
http://www.flickr.com/photos/stevehoble ... otostream/
http://www.flickr.com/photos/stevehoble ... otostream/
Posts: 2
Joined: Fri Oct 26, 2012 11:14 am
by shobley » Fri Oct 26, 2012 2:03 pm
UPDATE : Fixed it by installing the build-essentials package.

(And I've just discovered "Unity" in VMWare player - how flipping awesome is that...?)





...I'll get me coat.
Posts: 2
Joined: Fri Oct 26, 2012 11:14 am
by halhertani » Fri Oct 26, 2012 7:25 pm
Shobley,
Glad that you got it working!!!!

And yes Unity is awesome!!!....when it works.......
Posts: 40
Joined: Sun Aug 19, 2012 5:02 am
Location: Ottawa, ON Canada
by pygmy_giant » Sun Oct 28, 2012 11:10 am
might giver it a butchers for chibios
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by PeterO » Sat Nov 03, 2012 9:22 pm
I've down loaded the tool chain from git hub and set up the path as you describe on your web site, but when I try to compile "hello world" I get this....
Code: Select all
/home/ponion/opengles/userland/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../libexec/gcc/arm-linux-gnueabihf/4.7.2/cc1: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory

There is no libz.so.1 in the tool tree so the error is correct, but should there be a libz.so.1 somewhere in the tree ?
PeterO

FIXED IT !!!! The tools are all 32 bit, and I'm using them on a 64 bit machine. I needed to install the 32bit version of libz and now it works :-)
User avatar
Posts: 866
Joined: Sun Jul 22, 2012 4:14 pm
by halhertani » Sun Nov 04, 2012 1:28 am
PeterO,
yes you need to install the 32-bit libraries (ia32-libs package) if you're using a 64-bit version of the OS.
Glad it worked for you. Happy coding!

halhertani
Posts: 40
Joined: Sun Aug 19, 2012 5:02 am
Location: Ottawa, ON Canada
by gerkas » Mon Nov 12, 2012 12:44 pm
I followed the tutorial and successfully cross compiled a small testprogramm.
Now i want to write a programm which uses libusb and i am not able to crosscompile this library.
I did:
./configure --target=arm-linux-gnueabihf --prefix=/home/kag/raspberrypi//tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian
make
make install
This builds and installs libusb into .../gcc-linaro-arm-linux-gnueabihf-raspbian/ and everything seems ok.
But when i try to build my project in eclipse, i get an error message like "File format not recognized".

Is my idea correct, that i have to build libusb for the target (here raspberry) and then link my project against it?
How do i correctly build a library for raspberry?
Posts: 3
Joined: Mon Nov 12, 2012 7:11 am
by gerkas » Mon Nov 12, 2012 9:29 pm
Update:
I think i solved the problem myself.
./configure --host=arm-linux-gnueabihf --prefix=/home/kag/sdb1/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian
The specification of the target has to be in the parameter 'host'. I don't understand why, but reading config.log and a post in another forum brought me to this idea.
Now my project was built successfully in eclipse linked against a libusb version for arm linux.
I hope i will actually run on pi.
Posts: 3
Joined: Mon Nov 12, 2012 7:11 am
by halhertani » Wed Nov 14, 2012 12:16 am
gerkas,
Glad you were able to compile libusb with the cross compiler.....It would be awesome if you could report back if you were able to run libusb based code on the RPi or not.

Also I've been interested in messing around with USB programming using libUSB. Is there a libUSB tutorial out there that you recommend for beginners?
Posts: 40
Joined: Sun Aug 19, 2012 5:02 am
Location: Ottawa, ON Canada
by gerkas » Wed Nov 14, 2012 11:47 am
Hello,
my testprogramm worked on the raspberry.

I used this tutorial (http://www.dreamincode.net/forums/topic ... libusb-10/) and that's what my testprogramm does at the moment.
Later i want to communicate with a special hardware with data transfers (control_transfer, bulk_transfer). But i need more time for that.

And here is more information:
http://libusb.org/

Thanks for your tutorial which makes it easy to start c programming for the pi.
Posts: 3
Joined: Mon Nov 12, 2012 7:11 am
by falco152 » Sat Nov 17, 2012 12:04 am
Have anyone gotten any luck getting the "C library for Broadcom BCM 2835 as used in Raspberry Pi " to compile and install?

I tried gerkas's configure parameters on bcm2835 configure.

It breaks on make install when using --target.

I used --host, but it throws undefined references, even though I added their include and lib paths.

I keep tinkering with it. Would be nice to have some more insight to get it to cross compile.
Posts: 7
Joined: Fri Nov 16, 2012 10:57 pm
by halhertani » Mon Nov 19, 2012 8:38 pm
gerkas,
Your most welcome! I'm glad to be able to help. I've also posted a tutorial on using C++ to access GPIO (sysfs)

http://hertaville.com/2012/11/18/introduction-to-accessing-the-raspberry-pis-gpio-in-c/

And will be posting an eclipse remote debugging tutorial very soon!

falco,
Unfortunately I've have no experience with the BCM2835 library. But if you do have any luck setting it up I'd appreciate if you can share your experience with us!
Posts: 40
Joined: Sun Aug 19, 2012 5:02 am
Location: Ottawa, ON Canada
by falco152 » Tue Nov 20, 2012 12:41 am
No problem :D

At the moment, I just trying to figure out how to play with .configure to compile with your linkers.

If I figure it out before someone else, I post the solution.
Posts: 7
Joined: Fri Nov 16, 2012 10:57 pm
by falco152 » Mon Nov 26, 2012 7:00 pm
At the moment, my not so ideal workaround is just to slap the source code of bcm2835 as part of my project build path and enable Eclipse remote debugging as root.

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

I'm thinking the reason I'm unable to link originally because of the way I compiled lib bcm2835 which I think it static linked x86 lib rt instead of the armv6 lib rt.
Posts: 7
Joined: Fri Nov 16, 2012 10:57 pm
by nurquhar » Sun Jan 06, 2013 5:57 pm
I have followed the tutorial ok and I am able to create a "HelloWorld" binary. Debug & Release. Both appear to work correctly if use scp to copy to the pi and execute them there.

I have thus turned my efforts to trying to do a remote debug with Eclipse. What I want Eclipse to do when I launch debug is to copy the debug verison of the compiled binary to the RPi then start it with gdbserver. Eclipse should then start "arm-linux-gnueabihf-gdb" on its side and switch to using the debug windows.

I have spent a few days trying to get this setup but so far I am not having much luck with it.

What I have done so far is use "Debug Configurations" to setup a new Launch under "C/C++ Remote Application".
In the "main" tab I have the project and application set and in the "connection" I have the "raspberrypi" set as the remote machine along with a path to put its files. I also have "automatic" selected in GDB (DSF) option.
In the "Debugger" tab I have put "arm-linux-gnueabihf-gdb" as GDB debugger and I set the path to "/usr/bin/gdbserver" so it knows where gdbserver is on the remote.

However after trying to launch I get the following errors :
Error during file upload.
Missing element for : ''
Missing element for : ''
Missing element for : ''


Has anyone got remote debugging working from eclipse ? If so how ?
Posts: 16
Joined: Thu May 10, 2012 7:11 pm
by tibi38 » Tue Jan 08, 2013 12:57 pm
HI,
has anyone out there a solution for using cross-compiling with eclipse on windows and the new december built? There the standard for libs is using VFR registers and in my solution for cross compiling with the sourcery compiler the -mfloat-abi=hard is not supported (omly in the comercial version).
br
T.
Admin of http://bed-and-breakfast-ungarn.de
Posts: 40
Joined: Sat Nov 10, 2012 8:46 am
Location: Europe
by ZArie » Tue Jan 08, 2013 2:56 pm
hi halhertani,
I followed your great and detailed directions on how to install the Eclipse and the cross complier, I also somehow misinterpreted the idea that the include paths and the lib paths needs to be inserted manually to the eclipse.
My question is once this (include paths and lib paths) is done how that configuration can be maintained/applied for every new project that will be opened in that Eclipse ? can this be set as a default configuration for all new projects, instead of having to define it for every project ?
Thanks,
Arie
Posts: 5
Joined: Sat Aug 04, 2012 11:15 am