Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-compiling C++11 code for Raspberry Pi

I'm trying to port a large project, which makes heavy use of C++11 features, to the Raspberry Pi. The project uses CMAKE and I'm using crosstool-ng for the cross-compiling. I installed dependencies on the Pi and copied them locally, and I've managed to get CMAKE to find those. Some of the code builds properly and produces ARM output. However, most of the code fails with confusing GCC output that I'm pretty sure has to do with C++11/template support. For example, I get errors like this:

  • error: 'mutex' in namespace 'std' does not name a type (the file in question includes <thread> and this error goes away if I also include <mutex>, not a requirement on x86 Ubuntu)

  • error: expected class-name before '{' token (the line before { is: template<typename _Res> class __basic_future : public std::__future_base)

  • error: '__result_type' does not name a type (this probably happens because of the error above)

These errors look like the ARM g++ compiler just doesn't like templates that much. The version of g++ being used is arm-unknown-linux-gnueabi-g++ (crosstool-NG 1.18.0) 4.7.3 20130102 (prerelease).

Can anyone point me in the right direction?

Edit: Here's what g++ looks like for one of the files in ps:

arm-unknown-linux-gnueabi-g++ -DprojectCore_EXPORTS -fPIC
-I/home/sagar/workspace/RaspberryPi/target_env/usr/include
-I/home/sagar/workspace/RaspberryPi/target_env/usr/include/freetype2
-I/home/sagar/workspace/RaspberryPi/target_env/usr/include/glib-2.0
-I/home/sagar/workspace/RaspberryPi/target_env/usr/lib/arm-linux-gnueabihf/glib-2.0/include
-I/home/sagar/workspace/RaspberryPi/target_env/usr/include/gdk-pixbuf-2.0
-I/home/sagar/workspace/RaspberryPi/target_env/usr/include/gtk-2.0
-I/home/sagar/workspace/RaspberryPi/target_env/usr/lib/arm-linux-gnueabihf/gtk-2.0/include
-I/home/sagar/workspace/RaspberryPi/target_env/usr/include/cairo
-I/home/sagar/workspace/RaspberryPi/target_env/usr/include/pango-1.0
-I/home/sagar/workspace/RaspberryPi/target_env/usr/include/atk-1.0
-I/home/sagar/workspace/RaspberryPi/target_env/usr/local/include
-I/home/sagar/workspace/RaspberryPi/target_env/usr/include/eigen3
-I/home/sagar/workspace/RaspberryPi/target_env/usr/include/flann
-I/home/sagar/workspace/project/include -std=c++0x -Wall -Werror -Wno-deprecated -fPIC -g -O4
-o CMakeFiles/projectCore.dir/src/project/Core/Memory/Array2D.C.o -c /home/sagar/workspace/project/src/project/Core/Memory/Array2D.C
like image 406
sagargp Avatar asked Apr 14 '13 21:04

sagargp


People also ask

Can you write C code on Raspberry Pi?

C programming language is easy to write, learn and fast language that offers tons of libraries. Raspberry Pi is one of devices that can run and execute C programs in a very less complex way.

Can GCC cross compile?

For instance when installing GCC, the GNU Compiler Collection, we can use --target= target to specify that we want to build GCC as a cross-compiler for target . Mixing --build and --target , we can cross-compile a cross-compiler; such a three-way cross-compilation is known as a Canadian cross.


2 Answers

The only things I think are:

  • set -std=c++0x param to g++ compiler
  • link pthread (-lpthread)
  • you must be sure that you're compiling for armv6
like image 111
Delayer Avatar answered Oct 27 '22 00:10

Delayer


Let me start by saying I am not sure about the fix for this error. But I had seen a similar error while working with C++ in RPi for a large image processing code. I couldn't fix it by installing all the dependencies in time. Instead I ended up moving the entire code to cloud that was running windows server edition / windows 7 code where it compiled well. Just workaround idea if you are time bound!

like image 29
LogRCubed Avatar answered Oct 26 '22 22:10

LogRCubed