C++ 链接上的未定义符号 ___gxx_personality_v0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/203548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Undefined Symbol ___gxx_personality_v0 on link
提问by ryan_s
I've been getting this undefined symbol building with this command line:
我一直在用这个命令行构建这个未定义的符号:
$ gcc test.cpp
Undefined symbols:
"___gxx_personality_v0", referenced from:
etc...
test.cpp is simple and should build fine. What is the deal?
test.cpp 很简单,应该可以很好地构建。交易是什么?
回答by ryan_s
Use
用
g++ test.cpp
instead, since this is c++ code.
相反,因为这是 C++ 代码。
Or, if you reallywant to use gcc
, add -lstdc++
to the command line, like so:
或者,如果您真的想使用gcc
,请添加-lstdc++
到命令行,如下所示:
gcc test.cpp -lstdc++
Running md5
against the a.out
produced under each scenario shows that it's the same output.
md5
针对a.out
每个场景下的生产运行表明它是相同的输出。
But, yeah, g++
probably makes your world a simpler place.
但是,是的,g++
可能会让你的世界变得更简单。
回答by garageàtrois
The .cpp
extension causes gcc
to compile your file as a C++ file. (See the GCC docs.)
该.cpp
扩展导致gcc
将您的文件编译为 C++ 文件。(请参阅GCC 文档。)
Try compiling the same file, but rename it to have a .c
extension:
尝试编译相同的文件,但将其重命名为具有.c
扩展名:
mv test.cpp
gcc test.c
Alternatively, you can explicitly specify the language by passing -x c
to the compiler:
或者,您可以通过传递-x c
给编译器来显式指定语言:
gcc -x c -c test.cpp -o test.o
If you run nm test.o
on these C-language versions, you'll notice that ___gxx_personality_v0
is not listed as a symbol.
(And if you run the same command on an object file generated with gcc -c test.cpp -o test.o
, the ___gxx_personality_v0
symbol is present.)
如果您nm test.o
在这些 C 语言版本上运行,您会注意到它___gxx_personality_v0
没有作为符号列出。
(如果您在使用 生成的目标文件上运行相同的命令gcc -c test.cpp -o test.o
,则该___gxx_personality_v0
符号存在。)
回答by inket
Just in case anyone has the same problem as me: The file extension should be a .c
not a .C
(gcc is case-sensitive).
以防万一有人和我有同样的问题:文件扩展名应该.c
不是 a .C
(gcc 区分大小写)。
回答by BadPirate
Had the same problem, but a different solution:
有同样的问题,但不同的解决方案:
C++ code in static library getting linked, and being referenced by a .m file. Renaming the .m file to .mm fixed the issue.
静态库中的 C++ 代码被链接,并被 .m 文件引用。将 .m 文件重命名为 .mm 修复了该问题。