使用g ++时,包含C ++系统头文件的正确方法 - arm-linux-gnueabi?

时间:2014-09-28 20:54:50

标签: c++ linux g++ cross-compiling

我正在尝试在安装了软件包gcc-arm-linux-gnueabig++-arm-linux-gnueabi的Ubuntu 14.04上编译库。

编译在遇到的第一个源文件上失败:

/usr/bin/arm-linux-gnueabi-g++ -DNDEBUG -g2 -Os -pipe -fPIC -I. -DCRYPTOPP_DISABLE_ASM 
-mcpu=cortex-m3 -mthumb --sysroot=/usr/arm-linux-gnueabi -c 3way.cpp
In file included from cryptlib.h:83:0,
                 from seckey.h:8,
                 from 3way.h:7,
                 from 3way.cpp:5:
stdcpp.h:14:18: fatal error: memory: No such file or directory
compilation terminated.

当我执行find时,我看到C ++标题位于:

$ find /usr -name memory
/usr/arm-linux-gnueabi/include/c++/4.7.3/tr1/memory
/usr/arm-linux-gnueabi/include/c++/4.7.3/memory
/usr/arm-linux-gnueabi/include/c++/4.7.3/ext/memory
...

/usr/arm-linux-gnueabi已作为SYSROOT提供:

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

添加isysroot无济于事:

/usr/bin/arm-linux-gnueabi-g++ -DNDEBUG -g2 -Os -pipe -fPIC -DCRYPTOPP_DISABLE_ASM
-mcpu=cortex-m3 -mthumb -isysroot=/usr/arm-linux-gnueabi/include/c++/4.7.3
--sysroot=/usr/arm-linux-gnueabi -c 3way.cpp
In file included from cryptlib.h:83:0,
                 from seckey.h:8,
                 from 3way.h:7,
                 from 3way.cpp:5:
stdcpp.h:14:18: fatal error: memory: No such file or directory

我已经在其他平台(如Android,iOS和Windows Phone)上交叉编译了库,所以我很清楚需要做什么。这是我第一次使用arm-linux-gnueabi

使用g++-arm-linux-gnueabi包时,包含C ++标头和库的正确方法是什么?

相关:spec文件不应该处理这个吗?


编辑:这里有-v的一些相关信息。这些内置路径看起来不健康。看起来工具链正在尝试形成C ++标头的路径,但它没有做得很好:

/usr/bin/arm-linux-gnueabi-g++ -v -DNDEBUG -g2 -Os -pipe -fPIC -DCRYPTOPP_DISABLE_ASM 
-mcpu=cortex-m3 -mthumb --sysroot=/usr/arm-linux-gnueabi -c 3way.cpp

...
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "=/usr/arm-linux-gnueabi/include/c++/4.7.3/usr/arm-linux-gnueabi/include/c++/4.7.3"
ignoring nonexistent directory "=/usr/arm-linux-gnueabi/include/c++/4.7.3/usr/arm-linux-gnueabi/include/c++/4.7.3/arm-linux-gnueabi/sf"
ignoring nonexistent directory "=/usr/arm-linux-gnueabi/include/c++/4.7.3/usr/arm-linux-gnueabi/include/c++/4.7.3/backward"
ignoring nonexistent directory "=/usr/arm-linux-gnueabi/include/c++/4.7.3/usr/local/include/arm-linux-gnueabi"
ignoring nonexistent directory "=/usr/arm-linux-gnueabi/include/c++/4.7.3/usr/include/arm-linux-gnueabi"
ignoring nonexistent directory "=/usr/arm-linux-gnueabi/include/c++/4.7.3/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/include
 /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/include-fixed
 /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/include
End of search list.
GNU C++ (Ubuntu/Linaro 4.7.3-12ubuntu1) version 4.7.3 (arm-linux-gnueabi)
...

编辑:这看起来像是工具链使用的内部路径中的错误。在内置路径中,请注意路径中有一个额外的/usr/arm-linux-gnueabi。以下答案提供了一种解决方法。

向Ubuntu提交的错误报告:g++-arm-linux-gnueabi cannot compile a C++ program with --sysroot

1 个答案:

答案 0 :(得分:2)

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "=/usr/arm-linux-gnueabi/include/c++/4.7.3/usr/arm-linux-gnueabi/include/c++/4.7.3"
ignoring nonexistent directory "=/usr/arm-linux-gnueabi/include/c++/4.7.3/usr/arm-linux-gnueabi/include/c++/4.7.3/arm-linux-gnueabi/sf"
ignoring nonexistent directory "=/usr/arm-linux-gnueabi/include/c++/4.7.3/usr/arm-linux-gnueabi/include/c++/4.7.3/backward"
ignoring nonexistent directory "=/usr/arm-linux-gnueabi/include/c++/4.7.3/usr/local/include/arm-linux-gnueabi"
ignoring nonexistent directory "=/usr/arm-linux-gnueabi/include/c++/4.7.3/usr/include/arm-linux-gnueabi"
ignoring nonexistent directory "=/usr/arm-linux-gnueabi/include/c++/4.7.3/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/include
 /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/include-fixed
 /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/include
End of search list.
GNU C++ (Ubuntu/Linaro 4.7.3-12ubuntu1) version 4.7.3 (arm-linux-gnueabi)
...

这看起来像工具链使用的内部路径中的错误。在内置路径中,请注意路径中有额外的/usr/arm-linux-gnueabi。向Ubuntu提交的错误报告:g++-arm-linux-gnueabi cannot compile a C++ program with --sysroot

要解决此问题,应使用-I显式添加C ++标头的路径:

  • /usr/arm-linux-gnueabi/include/c++/4.7.3
  • /usr/arm-linux-gnueabi/include/c++/4.7.3/arm-linux-gnueabi

在与--sysroot链接时,无需指定C和C ++库,因为该选项可以正确处理它们。

因此编译/链接命令看起来类似于:

/usr/bin/arm-linux-gnueabi-g++ ... -mcpu=cortex-m3 -mthumb \
  -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 test.cpp -o test.exe