C++ 在使用gcc的工具链中,首选sysroot头而不是头
我试图交叉编译一个简单的代码片段C++ 在使用gcc的工具链中,首选sysroot头而不是头,c++,linux,compiler-errors,cross-compiling,C++,Linux,Compiler Errors,Cross Compiling,我试图交叉编译一个简单的代码片段 1 #include <sys/socket.h> 2 #include <stdio.h> 3 4 int main() 5 { 6 printf("%d\n", SOL_NETLINK); 7 return 0; 8 } 即使$SYSROOT/usr/include/arm-linux-gnueabihf/bits/socket.h包含 所需的定义 所以我认为toolchain也包含前
1 #include <sys/socket.h>
2 #include <stdio.h>
3
4 int main()
5 {
6 printf("%d\n", SOL_NETLINK);
7 return 0;
8 }
即使$SYSROOT/usr/include/arm-linux-gnueabihf/bits/socket.h
包含
所需的定义
所以我认为toolchain也包含前面提到的标题,它是第一个包含的。后一个标头不知何故没有定义此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)
#include
将包含文件夹{include path}/sys/socket.h
下的文件
Include path可以是使用各种选项添加的任何文件夹,如gcc-I
或-includedir
。此外,还有一些默认的include路径,您应该能够通过gcc-xc++-E-v-
看到这些路径
使用gcc“-I”选项将把要搜索的include路径放在第一位,在任何默认include路径之前
现在,这应该为您提供足够的信息,让您了解您提供的include不能指向文件$SYSROOT/usr/include/arm-linux-gnueabihf/bits/socket.h
,因为它不是以{include path}/sys/socket.h
\include
结束的,它将包含文件夹{include path}下的一个文件/sys/socket.h
Include path可以是使用各种选项添加的任何文件夹,如gcc-I
或-includedir
。此外,还有一些默认的include路径,您应该能够通过gcc-xc++-E-v-
看到这些路径
使用gcc“-I”选项将把要搜索的include路径放在第一位,在任何默认include路径之前
现在,这应该为您提供足够的信息,让您理解您提供的include不能指向文件
$SYSROOT/usr/include/arm-linux-gnueabihf/bits/socket.h
,因为它不是以{include path}/sys/socket.h
结尾,而是使用-issystem标志和$SYSROOT/usr/include/arm-linux-gnueabihf
尽管GCC可以解析路径中的triple(arm linux gnueabihf部分),但它不能使用--sysroot选项进行解析。使用带$sysroot/usr/include/arm linux gnueabihf的-isystem标志 尽管GCC可以解析路径中的triple(arm linux gnueabihf部分),但它不能使用--sysroot选项进行解析。检查
--sysroot
选项的可能重复项。检查--sysroot
选项的可能重复项。
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)