在cygwin中使用clang的神秘链接器错误"undefined reference to `__gxx_personality_v0'"
Mysterious linker error "undefined reference to `__gxx_personality_v0'" using clang in cygwin
我做了一些搜索,所有答案似乎都表明使用clang++而不是clang(或者更确切地说是g++代替gcc),这就是我首先所做的。尽管如此,问题仍然存在,要么
clang++ -Wall -std=c++11 -o test.exe test.cpp A.cpp B.cpp etc.cpp
或
clang++ -lstdc++ -Wall -std=c++11 -o test.exe test.cpp A.cpp B.cpp etc.cpp
编译和链接在Cygwin中的g++上运行良好。
g++ -Wall -std=c++11 -o test.exe test.cpp A.cpp B.cpp etc.cpp
更新:
这是链接期间的信息。clang是否试图使用gcc而不是g++进行链接?在这种情况下,为什么标记 -lstdc++ 和下面建议的 -lsupc++ 不起作用?
COMPILER_PATH=/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/:/usr/lib/gcc/x86_64-pc-cygwin/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/:/usr/lib/gcc/x86_64-pc-cygwin/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/lib/../lib/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/lib/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-m64' '-o' 'testReSampling.exe' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/collect2.exe --build-id -m i386pep --wrap _Znwm --wrap _Znam --wrap _ZdlPv --wrap _ZdaPv --wrap _ZnwmRKSt9nothrow_t --wrap _ZnamRKSt9nothrow_t --wrap _ZdlPvRKSt9nothrow_t --wrap _ZdaPvRKSt9nothrow_t -Bdynamic --dll-search-prefix=cyg --tsaware -o testReSampling.exe /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../lib/crt0.o /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/crtbegin.o -L/usr/lib/gcc/x86_64-pc-cygwin/4.8.3 -L/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/lib/../lib -L/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/lib -L/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../.. -lsupc++ /tmp/misc-8020e8.o /tmp/DataStruct-b10944.o /tmp/HyperGeometricPVal-edef1c.o /tmp/Array2EG-3441bb.o /tmp/GOCats-ff22c1.o /tmp/UGraph-10cfd8.o /tmp/testReSampling-9fb18c.o -lstdc++ -lgcc_s -lgcc -lcygwin -ladvapi32 -lshell32 -luser32 -lkernel32 -lgcc_s -lgcc /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../lib/default-manifest.o /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/crtend.o
/tmp/misc-8020e8.o:fake:(.eh_frame+0x47): undefined reference to `__gxx_personality_v0'
/tmp/misc-8020e8.o:fake:(.eh_frame$_ZNSt6vectorISsSaISsEE5clearEv+0x13): undefined reference to `__gxx_personality_v0'
/tmp/misc-8020e8.o:fake:(.eh_frame$_ZNSt6vectorISt4pairIjS0_ItdEESaIS2_EE5beginEv+0x13): undefined reference to `__gxx_personality_v0'
/tmp/misc-8020e8.o:fake:(.eh_frame$_ZNSt6vectorISt4pairIjS0_ItdEESaIS2_EE3endEv+0x13): undefined reference to `__gxx_personality_v0'
/tmp/misc-8020e8.o:fake:(.eh_frame$_ZNSt6vectorISt4pairIjS0_ItSt5arrayIdLm2EEEESaIS4_EE5beginEv+0x13): undefined reference to `__gxx_personality_v0'
/tmp/misc-8020e8.o:fake:(.eh_frame$_ZNSt6vectorISt4pairIjS0_ItSt5arrayIdLm2EEEESaIS4_EE3endEv+0x13): more undefined references to `__gxx_personality_v0' follow
collect2: error: ld returned 1 exit status
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
找到这个解决方案:
https://cygwin.com/ml/cygwin/2015-06/msg00294.html
基本上,编译时只需在命令行上添加-fno-exceptions
clang++ helloworld.cpp -std=c++11 -fno-exceptions
好的,当我进一步在网上徘徊时,我找到了一个相关的帖子,看看 nos 的答案。
所以我意识到我是在用 Cygwin64 终端编译的,而 Cygwin 的 clang 端口是 32 版本。切换到Cygwin32终端后,一切正常。
尝试:clang++ -fno-exceptions -Xclang -fcxx-exceptions
或clang++ -Xclang -fseh-exceptions
相关文章:
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- Visual Studio Code "undefined reference to `WinMain@16'"
- 使用 MATLAB 编码器生成C++代码:编译错误"undefined reference to `rgb2gray_tbb_real64'"
- 为什么创建友元类的实例会导致"undefined reference to"错误?
- Tensorflow c++ api undefined reference to 'tflite::D efaultErrorReporter()'
- 为什么在使用 SDL2 时仍然收到'undefined reference'链接器错误?
- OpenCV undefined reference to 'cv::imread(cv::String const&, int)'
- Libcurl c++ "undefined reference to" (Windows/MinGW/g++)
- 尝试使用 extern "C" 调用 C 中的C++方法,得到"undefined reference to"对象的链接器错误
- build error : undefined reference to `yyFlexLexer::yyFlexLex
- 安卓 NDK 制造。数百"undefined reference error"
- 当我尝试进行TPC-E测试时,实用程序抱怨"undefined reference"
- 声明和定义函数静态会产生"undefined reference to function_name()"
- C++ : "undefined reference to"可能是因为CMake文件
- 包含<iostream>时"Undefined reference"错误
- CMake 'undefined reference' CERN-ROOT 的错误
- 生成错误:"cannot find target for file"和"undefined reference"
- AppData\Local\Temp\cc59LXDc.o:test1.cpp: undefined reference to 'constructNewObjectOfClass
- YAML-cpp 编译错误:"undefined reference to YAML::LoadFile"
- 添加 cpp11 插件时出现错误消息"Undefined reference to boost (...)"