I have set up the cross compiler for Raspberry pi in ubuntu. Also, I have followed steps mentioned in this blog to set up eclipse.

When I compile a plain Hello World program, it compiles fine. But if I include a header file that is available in sysroot folder, it doesn't include that header to compile it.

For example,consider the code :

#include <iostream>
using namespace std;
#include <dbus/dbus-arch-deps.h>
int main() {
   cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
   return 0;

When I compile this code, it fails to include the file dbus-arch-deps.h. Compile command is :

22:42:51 **** Build of configuration Debug for project HelloWorld ****
make all
Building file: ../src/HelloWorld.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include/ -O0 -g3 -Wall -c -fmessage-length=0 --sysroot=/home/ashwa/Documents/raspberrypi2-sysroot/ -MMD -MP -MF"src/HelloWorld.d" -MT"src/HelloWorld.d" -o "src/HelloWorld.o" "../src/HelloWorld.cpp"
../src/HelloWorld.cpp:11:33: fatal error: dbus/dbus-arch-deps.h: No such file or directory
 #include <dbus/dbus-arch-deps.h>
compilation terminated.
src/subdir.mk:18: recipe for target 'src/HelloWorld.o' failed
make: *** [src/HelloWorld.o] Error 1

However, the header file is available in /home/ashwa/Documents/raspberrypi2-sysroot//usr/lib/arm-linux-gnueabihf/dbus-1.0/include/ but the compiler is not finding it.

As per this link , it says that if the compiler was built --with-sysroot, then compiler will not include the sysroot mentioned in gcc or g++ command. And, I can see that my compiler is built --with-sysroot

Using built-in specs.
Target: arm-linux-gnueabihf
Configured with: /cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/src/gcc-linaro-4.8-2014.01/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu --target=arm-linux-gnueabihf --prefix=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install --with-sysroot=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-languages=c,c++,fortran --disable-multilib --enable-multiarch --with-arch=armv6 --with-tune=arm1176jz-s --with-fpu=vfp --with-float=hard --with-pkgversion='crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11' --with-bugurl=https://bugs.launchpad.net/gcc-linaro --enable-__cxa_atexit --enable-libmudflap --enable-libgomp --enable-libssp --with-gmp=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpfr=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpc=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-isl=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-cloog=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-libelf=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --enable-threads=posix --disable-libstdcxx-pch --enable-linker-build-id --enable-plugin --enable-gold --with-local-prefix=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-c99 --enable-long-long --with-float=hard
Thread model: posix
gcc version 4.8.3 20140106 (prerelease) (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11) 

If this is the case, how can I include header files and libraries that are available in the sysroot to compile? Can anyone please suggest me how to proceed further? Thanks in advance.

  • Quick comment: Throwing using namespace std in before an #include, even (or maybe especially...) if it is just a C include is probably a very bad idea, is very unlikely to serve a useful purpose, and even if it did, is debatably against the standard and/or exploiting loopholes in it and specific compiler implementations: stackoverflow.com/q/6841130/1151724 – goldilocks Dec 3 '16 at 15:11
  • Thank you for your comment. I will take care of it. Any suggestions about the main problem? – user6930414 Dec 3 '16 at 16:00
  • Your include path setup must be wrong – John Keates Dec 4 '16 at 5:05
  • Hi John, Thank you for your response. I verified it, I can see that sysroot is in "/home/ashwa/Documents/raspberrypi2-sysroot/" and header file is in "/home/ashwa/Documents/raspberrypi2-sysroot/usr/lib/arm-linux-gnueabihf/dbus-1.0/include/". Since sysroot is included in g++ command, only "/usr/lib/arm-linux-gnueabihf/dbus-1.0/include/" is added. Paths are correct, is there anything wrong in the way it is mentioned in g++ command? – user6930414 Dec 4 '16 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.