错误:undefined reference to `__gxx_personality_v0'

本文介绍使用GCC编译包含C++库的C代码时出现的错误:undefined reference to `__gxx_personality_v0'。文章解释了此错误的原因,并提供了两种解决方案:一是使用g++代替gcc进行编译;二是如果坚持使用gcc,则需手动添加-lstdc++选项以链接C++标准库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用gcc编译C代码,引用了C++ 库,出现这个错误,网上搜到这哥们的文章,解决问题

转自:错误:undefined reference to `__gxx_personality_v0'

1. Linux Develop Notes

    * 编译 c++ 程序需要添加 -lstdc++   sample: gcc -lstdc++ -o test test.c,否则会报 "undefinedreference to '__gxx_personality_v0' " 错误

2. 唉,用gcc命令编译C程序,用g++命令编译C++程序。

g++和gcc本质一样的,本质上还是gcc,我们实验室所有的c++程序都是用gcc编译的,一般的程序用gcc足够了。 对于 C++ 程序,编译的时候用 gcc 或者 g++ 都可以。但是在进行连接的时候最好用 g++,因为用 g++ 会自动进行 C++ 标准库的连接;用 gcc 连接 C++ 程序也可以,但是需要人为指定连接 C++ 标准库,否则就会出现 undefined reference to `__gxx_personality_v/0' 之类的错误。

可见-lstdc++ 所对应的是标准C++库

/usr/bin/ld: summinfo.cpp:(.text._ZN11xlslib_core10hpsf_doc_t7addItemEty[_ZN11xlslib_core10hpsf_doc_t7addItemEty]+0x59): undefined reference to `operator delete(void*)' /usr/bin/ld: ../../src/.libs/libxls.a(summinfo.o):(.rodata._ZTIN11xlslib_core12CSummaryInfoE[_ZTIN11xlslib_core12CSummaryInfoE]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info' /usr/bin/ld: ../../src/.libs/libxls.a(summinfo.o):(.eh_frame+0x13): undefined reference to `__gxx_personality_v0' /usr/bin/ld: ../../src/.libs/libxls.a(colinfo.o): in function `xlslib_core::CColInfo::~CColInfo()': colinfo.cpp:(.text+0x192): undefined reference to `operator delete(void*)' /usr/bin/ld: ../../src/.libs/libxls.a(colinfo.o): in function `__static_initialization_and_destruction_0(int, int)': colinfo.cpp:(.text+0x1bf): undefined reference to `std::ios_base::Init::Init()' /usr/bin/ld: colinfo.cpp:(.text+0x1ce): undefined reference to `std::ios_base::Init::~Init()' /usr/bin/ld: ../../src/.libs/libxls.a(colinfo.o):(.rodata._ZTIN11xlslib_core8CColInfoE[_ZTIN11xlslib_core8CColInfoE]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info' /usr/bin/ld: ../../src/.libs/libxls.a(colinfo.o):(.eh_frame+0x4b): undefined reference to `__gxx_personality_v0' /usr/bin/ld: ../../src/.libs/libxls.a(continue.o): in function `xlslib_core::CContinue::~CContinue()': continue.cpp:(.text+0x116): undefined reference to `operator delete(void*)' /usr/bin/ld: ../../src/.libs/libxls.a(continue.o): in function `__static_initialization_and_destruction_0(int, int)': continue.cpp:(.text+0x143): undefined reference to `std::ios_base::Init::Init()' /usr/bin/ld: continue.cpp:(.text+0x152): undefined reference to `std::ios_base::Init::~Init()' /usr/bin/ld: ../../src/.libs/libxls.a(continue.o):(.rodata._ZTIN11xlslib_core9CContinueE[_ZTIN11xlslib_core9CContinueE]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info' /usr/bin/ld: ../../src/.libs/libxls.a(continue.o):(.eh_frame+0x6b): undefined reference to `__gxx_personality_v0' collect2: error: ld returned 1 exit status make[2]: *** [Makefile:590:testC] 错误 1 make[2]: 离开目录“/home/zhu/桌面/xlslib/xlslib/targets/test” make[1]: *** [Makefile:322:all-recursive] 错误 1 make[1]: 离开目录“/home/zhu/桌面/xlslib/xlslib/targets” make: *** [Makefile:418:all-recursive] 错误 1 make xlslib出现的
03-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值