g++-arm-linux-gnueabi cannot compile a C++ program with --sysroot

Bug #1375071 reported by Jeffrey Walton on 2014-09-29
This bug affects 5 people
Affects Status Importance Assigned to Milestone
gcc-defaults-armel-cross (Ubuntu)
gcc-defaults-armhf-cross (Ubuntu)

Bug Description

g++-arm-linux-gnueabi cannot compile a C++ program with --sysroot. It appears there are problems with the built-in paths used for the C++ headers.

The rest of the report just dumps information. But to summarize the dump...

We need the paths:

  A) /usr/arm-linux-gnueabi/include/c++/4.7.3
  B) /usr/arm-linux-gnueabi/include/c++/4.7.3/arm-linux-gnueabi

But the built-in paths tries to use:

  C) /usr/arm-linux-gnueabi/usr/arm-linux-gnueabi/include/c++/4.7.3
  D) /usr/arm-linux-gnueabi/usr/arm-linux-gnueabi/include/c++/4.7.3/arm-linux-gnueabi/sf
  E) /usr/arm-linux-gnueabi/usr/arm-linux-gnueabi/include/c++/4.7.3/backward

Notice the built-in paths use an extra "/usr/arm-linux-gnueabi"


Ubuntu 14.04 (x64), fully patched. gcc-arm-linux-gnueabi and g++-arm-linux-gnueabi are installed.

$ uname -sm
Linux x86_64

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Codename: trusty


$ /usr/bin/arm-linux-gnueabi-g++ --version
arm-linux-gnueabi-g++ (Ubuntu/Linaro 4.7.3-12ubuntu1) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.


$ ls /usr/arm-linux-gnueabi
bin include lib


$ cat embedded.cpp
#include <iostream>

int main(int argc, char* argv[])
    std::cout << "Hello World" << std::endl;
    return 0;


$ /usr/bin/arm-linux-gnueabi-g++ --sysroot=/usr/arm-linux-gnueabi embedded.cpp -o embedded.exe
embedded.cpp:1:20: fatal error: iostream: No such file or directory
compilation terminated.


It appears the C++ headers are not included with SYSROOT. If I add the C++ header paths, then the compile is successful:

$ /usr/bin/arm-linux-gnueabi-g++ -I/usr/arm-linux-gnueabi/include/c++/4.7.3 -I/usr/arm-linux-gnueabi/include/c++/4.7.3/arm-linux-gnueabi --sysroot=/usr/arm-linux-gnueabi embedded.cpp -o embedded.exe


$ /usr/bin/arm-linux-gnueabi-readelf readelf -h ./embedded.exe | grep -i 'class\|machine'
readelf: Error: 'readelf': No such file
  Class: ELF32
  Machine: ARM


From http://wiki.ubuntu.com/ToolChain:

$ /usr/bin/arm-linux-gnueabi-g++ -v -E - < /dev/null 2>&1 | awk '/^#include/,/^End of search/' | grep '^ '


However, there's actually more to the paths than shown on ToolChain wiki, and this shows the incorrect C++ lookups. There's an extra '/usr/arm-linux-gnueabi/' in the paths being used:

$ /usr/bin/arm-linux-gnueabi-g++ -v --sysroot=/usr/arm-linux-gnueabi embedded.cpp -o embedded.exe
Using built-in specs.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/arm-linux-gnueabi/usr/arm-linux-gnueabi/include/c++/4.7.3"
ignoring nonexistent directory "/usr/arm-linux-gnueabi/usr/arm-linux-gnueabi/include/c++/4.7.3/arm-linux-gnueabi/sf"
ignoring nonexistent directory "/usr/arm-linux-gnueabi/usr/arm-linux-gnueabi/include/c++/4.7.3/backward"
ignoring nonexistent directory "/usr/arm-linux-gnueabi/usr/local/include/arm-linux-gnueabi"
ignoring nonexistent directory "/usr/arm-linux-gnueabi/usr/include/arm-linux-gnueabi"
ignoring nonexistent directory "/usr/arm-linux-gnueabi/usr/include"
#include "..." search starts here:
#include <...> search starts here:
End of search list.


$ /usr/bin/arm-linux-gnueabi-g++ -v
Using built-in specs.
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.3-12ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/arm-linux-gnueabi/include/c++/4.7.3 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-gnu-unique-object --disable-libmudflap --disable-libitm --enable-plugin --with-system-zlib --enable-objc-gc --with-cloog --enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv5t --with-float=soft --disable-werror --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabi --program-prefix=arm-linux-gnueabi- --includedir=/usr/arm-linux-gnueabi/include
Thread model: posix
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-12ubuntu1)

Jeffrey Walton (noloader) wrote :

Just in case... Both of these produced the error (so it was not the "=" sign after SYSROOT):

/usr/bin/arm-linux-gnueabi-g++ --sysroot=/usr/arm-linux-gnueabi embedded.cpp -o embedded.exe

/usr/bin/arm-linux-gnueabi-g++ --sysroot /usr/arm-linux-gnueabi embedded.cpp -o embedded.exe

Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in gcc-defaults-armel-cross (Ubuntu):
status: New → Confirmed
Changed in gcc-defaults-armhf-cross (Ubuntu):
status: New → Confirmed
Denis Borisevich (dennisfen) wrote :

Got the same problem on Ubuntu 15.04 with gcc-arm-linux-gnueabihf-4.9

Jeffrey Walton (noloader) wrote :

As Denis stated in Comment #4, this problem appears in ARMHF toolchain, also.

See, for example:

 * "Linking error when compiling Crypto++ for ARMHF", http://stackoverflow.com/q/31698241
 * "Crypto++ Issue 134: setenv-embedded.sh and GNUmakefile-cross", http://github.com/weidai11/cryptopp/issues/134

Its just an FYI comment, and the ARMHF toolchain may need a separate bug report. But I'm guessing what has been done in one toolchain is done in other toolchains. I can envision something like an errant staging $DESTDIR added in the wrong place.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers