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

时间:2021-10-15 00:17:42

I'm trying to compile a library on Ubuntu 14.04 with packages gcc-arm-linux-gnueabi and g++-arm-linux-gnueabi installed.

我正在尝试在Ubuntu 14.04上编译一个包含gcc-arm-linux-gnueabi和g++-arm-linux-gnueabi的库。

The compile fails on the first source file it encounters:

在第一个源文件中,编译失败:

/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.

When I perform a find I see that the C++ headers are located at:

当我执行一个发现时,我看到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 is already provided as SYSROOT:

/usr/arm-linux-gnueabi已经提供了SYSROOT:

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

Adding an isysroot does not help:

添加一个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

I've cross compiled the library on other platforms (like Android, iOS and Windows Phone), so I have a good idea of what needs to be done. This is my first time with arm-linux-gnueabi, however.

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

What is the proper way to include C++ headers and libraries when using the g++-arm-linux-gnueabi package?

在使用g++-arm-linux-gnueabi包时,正确的方式应该包括c++头和库吗?

Related: shouldn't a spec file already handle this?

相关:规范文件不应该已经处理了吗?


EDIT: here's some related information with -v. These built-in paths look unhealthy. It looks like the toolchain is trying to form the path to the C++ headers, but its not doing a good job:

编辑:这里有一些与-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)
...

Edit: this looks like a bug in the internal paths used by the toolchain. In the built-in paths, notice there's an extra /usr/arm-linux-gnueabi in the path. The answer below provides a workaround.

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

Bug report filed with Ubuntu: g++-arm-linux-gnueabi cannot compile a C++ program with --sysroot.

Bug报告:g++-arm-linux-gnueabi不能编译一个带有sysroot的c++程序。

1 个解决方案

#1


1  

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)
...

This looks like a bug in the internal paths used by the toolchain. In the built-in paths, notice there's an extra /usr/arm-linux-gnueabi in the path. Bug report filed with Ubuntu: g++-arm-linux-gnueabi cannot compile a C++ program with --sysroot.

这看起来像工具链使用的内部路径中的一个错误。在内置路径中,注意路径中有一个额外的/usr/arm-linux-gnueabi。Bug报告:g++-arm-linux-gnueabi不能编译一个带有sysroot的c++程序。

To work around the bug, the paths to the C++ headers should be added explicitly with -I:

要解决这个问题,应该显式地添加到c++头的路径。

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

There's no need to specify the C and C++ libraries when linking with --sysroot because the option handles them properly.

在与sysroot链接时,不需要指定C和c++库,因为选项可以正确地处理它们。

So a compile/link command would look similar to:

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

/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

#1


1  

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)
...

This looks like a bug in the internal paths used by the toolchain. In the built-in paths, notice there's an extra /usr/arm-linux-gnueabi in the path. Bug report filed with Ubuntu: g++-arm-linux-gnueabi cannot compile a C++ program with --sysroot.

这看起来像工具链使用的内部路径中的一个错误。在内置路径中,注意路径中有一个额外的/usr/arm-linux-gnueabi。Bug报告:g++-arm-linux-gnueabi不能编译一个带有sysroot的c++程序。

To work around the bug, the paths to the C++ headers should be added explicitly with -I:

要解决这个问题,应该显式地添加到c++头的路径。

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

There's no need to specify the C and C++ libraries when linking with --sysroot because the option handles them properly.

在与sysroot链接时,不需要指定C和c++库,因为选项可以正确地处理它们。

So a compile/link command would look similar to:

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

/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