使用GCC,优于工具链中的标头SYSROOT标头
Prefer sysroot headers over headers in the toolchain using gcc
我正在尝试交叉编译简单代码段
1 #include <sys/socket.h>
2 #include <stdio.h>
3
4 int main()
5 {
6 printf("%dn", SOL_NETLINK);
7 return 0;
8 }
使用Arm-linux-gnueabihf-g (来自ubuntu),与 --sysroot
开关设置为 $SYSROOT
汇编失败了此错误:
test.cpp:6:20: error: ‘SOL_NETLINK’ was not declared in this scope
即使$SYSROOT/usr/include/arm-linux-gnueabihf/bits/socket.h
包含所需的定义。
所以我认为工具链也包含上述标头,首先包含它。后者以某种方式没有此Sol_netLink定义。因此,我需要一种方法来告诉编译器更喜欢工具链的标题而不是Sysroot的标题。
> arm-linux-gnueabihf-g++ -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabihf/5/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-armhf-cross/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-armhf-cross --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-armhf-cross --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libgcj --enable-objc-gc --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --disable-werror --enable-multilib --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf- --includedir=/usr/arm-linux-gnueabihf/include
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4)
使用$ sysroot/usr/include/am arm-linux-gnueabihf
使用-isystem标志尽管GCC可以在路径中解决三重(Arm-linux-gnueabihf部分),但它不会使用-sysroot选项。
#include <sys/socket.h>
将包括一个文件夹 {include path}/sys/socket.h
下的文件。
包含路径可以是您添加的任何文件夹,其中包含各种选项,例如GCC -I
或--includedir
。此外,还有一些默认包含路径,您应该可以使用gcc -xc++ -E -v -
看到。
使用GCC" -i"选项将在任何默认值包含路径之前先搜索搜索路径。
。现在,这应该为您提供足够的信息,以了解包括您给出的包含指向文件$SYSROOT/usr/include/arm-linux-gnueabihf/bits/socket.h
,因为{include path}/sys/socket.h
相关文章:
- g++ 说函数不存在,即使包含正确的标头
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- 在CMake中使用find_package时,是否会显式包含标头
- 错误"Could not find Boost"(缺少:上下文标头)
- 如何在标头中声明(或定义)函数的问题
- 如何避免在仅标头库中C++类/变量重定义
- C++算法标头中,为什么要使用 "!(val < *first)" ?
- C++标头错误 C2238 意外标记";"
- std::initializer_list,大括号初始化和标头
- 在 c++ 中拆分类和标头中的继承,错误
- 如何确定哪个标头调用 c++ 中的另一个标头
- 如何在生成文件中添加多个标头 (HDR) 和对象?
- 我可以在运行时重新定义在 OpenCascade/OCCT 标头中定义的 c++ 静态常量吗?
- GCC,CMake,预编译标头和维护依赖项
- VisualStudio:使用 Suse Enterprise Server 12 SP5 时,不会下载远程库标头
- 一个标头库中的错误
- 可视化 Bazel C++预编译标头实现
- 如何在 CMake 中添加预编译标头用于 Visual Studio 生成器
- 使用 GN 构建预编译标头
- 使用GCC,优于工具链中的标头SYSROOT标头