使用-nodefaultlibs进行编译会导致Linux系统调用出现链接错误

时间:2017-07-21 02:36:16

标签: linux system-calls libc++

我需要使用自定义libc ++进行编译。所以我正在使用以下编译器标志:

-nostdinc++ -isystem ${MY_LIBCXX_INC}

这是链接器标志:

-nodefaultlibs  -L ${MY_LIBCXX_LIB} -lc++ -lc++abi -lm -lc -lgcc_s -lgcc

这会导致尝试使用#include <sys/stat.h>stat(path, buff)系统调用的任何调用出现链接错误。

如果我将-nodefaultlibs替换为-stdlib=libc++,我就不会收到此链接错误。

有人可以解释为什么会这样吗?理想情况下,我想强制执行-nodefaultlibs以绝对确保某些默认的libs(如libstdc ++或其他东西不会被链接到。)

更多信息 以下是使用-v选项的链接器的详细错误:

clang: warning: argument unused during compilation: '-nostdinc++'
 "/usr/bin/ld" -export-dynamic -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -export-dynamic -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o ../../output/bin/MavLinkTest /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crt1.o /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/crtbegin.o -L/home/shitals/GitHubSrc/AirSim/llvm-build/output/lib -L/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../.. -L/usr/lib/llvm-3.9/bin/../lib -L/lib -L/usr/lib -lc++ -lm -lc -lgcc_s -lgcc CMakeFiles/MavLinkTest.dir/home/shitals/GitHubSrc/AirSim/MavLinkCom/MavLinkTest/main.cpp.o CMakeFiles/MavLinkTest.dir/home/shitals/GitHubSrc/AirSim/MavLinkCom/MavLinkTest/UnitTests.cpp.o CMakeFiles/MavLinkTest.dir/home/shitals/GitHubSrc/AirSim/MavLinkCom/MavLinkTest/Commands.cpp.o -lpthread ../../output/lib/libMavLinkCom.a -lc++abi -lpthread /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/crtend.o /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crtn.o
../../output/lib/libMavLinkCom.a(FileSystem.cpp.o): In function `mavlink_utils::FileSystem::isDirectory(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)':
/home/shitals/GitHubSrc/AirSim/MavLinkCom/common_utils/FileSystem.cpp:144: undefined reference to `stat'
../../output/lib/libMavLinkCom.a(FileSystem.cpp.o): In function `mavlink_utils::FileSystem::exists(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)':
/home/shitals/GitHubSrc/AirSim/MavLinkCom/common_utils/FileSystem.cpp:158: undefined reference to `stat'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

0 个答案:

没有答案