打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
在初学C代码上隐藏编译器错误

g在我的项目的两行中发出了一个模糊的错误,未定义的对’__gxx_personality_sj0’的引用.在这种情况下,这意味着什么?我google了很多,发现这通常与在C中包含C代码或类似的东西有关,这不是我想要的. (我知道代码质量不高,但应该编译,我相信).

Projecto.cpp

#include "Projecto.h"#include <iostream>#include <iomanip>#include <string>Projecto::~Projecto() {} //THIS LINE GETS THAT ERRORvoid Projecto::adicionaVerba(float quantia){ verba =quantia; if(verba > verbamaxima)  verba -= quantia;}std::string Projecto::Tipo(){ //THIS LINE GETS THAT ERROR return "Projecto";}void Projecto::Imprime(){ Identificador::Imprime(); cout << verbamaxima << endl;}bool Projecto::operator> (const Projecto &proj2) const{ return proj2.verba > this->verba;}

Projecto.h

#ifndef PROJECTO_H_#define PROJECTO_H_#include <iostream>#include <iomanip>#include "Identificador.h"#include <string>#include <vector>using namespace std;class Projecto: public Identificador {protected:int verbamaxima;vector<string> projecto;float verba;public:Projecto(int verbamaxima = 0):Identificador("Projecto") {verba=0;}~Projecto();string Tipo();void Imprime();void adicionaVerba(float quantia);bool operator> (const Projecto &proj2) const;};#endif /* IDENTIFICADOR_H_ */

Identificador.cpp

#include "Identificador.h"using namespace std;#include <iostream>#include <iomanip>using namespace std;Identificador::Identificador(string nome):codigo(id){ Identificador::nome = nome; id =2;}Identificador::~Identificador(){}int Identificador::id = 1000;string Identificador::Tipo(){}void Identificador::Imprime(){ cout << Tipo() << endl; cout << Codigo() << endl; cout << Nome() << endl;}int Identificador::Codigo() const{ return codigo;}string Identificador::Nome(){ return nome;}

Identificador.h

#ifndef IDENTIFICADOR_H_#define IDENTIFICADOR_H_#include <iostream>#include <iomanip>using namespace std;class Identificador {protected:static int id;const int codigo;string nome;public:Identificador(string nome);virtual ~Identificador();virtual string Tipo();virtual void Imprime();int Codigo() const;string Nome();};#endif /* IDENTIFICADOR_H_ */

感谢您阅读此内容!

编辑:

我正在使用Eclipse和mingw工具链.我最近安装了Nuwen的Mingw发行版来代替官方发行版.编译项目,我得到它作为控制台输出(从未发生过):

**** Build of configuration Debug for project estudo_CI1 ******** Internal Builder is used for build               ****g   -oestudo_CI1.exe src\main.o src\Universidade.o src\Projecto.o src\Investigador.o src\Identificador.oWarning: .drectve `-aligncomm:___mingw_gMTRemoveKeyDtor,2 ' unrecognizedWarning: .drectve `-aligncomm:___mingw_gMTKeyDtor,2 ' unrecognizedWarning: .drectve `-aligncomm:___mingw_usemthread_dll,2' unrecognizedWarning: .drectve `-aligncomm:___hexdig_D2A,2' unrecognizedsrc\Projecto.o: In function `ZN8ProjectoD2Ev':C:/Users/Francisco/workspace_aeda/estudo_CI1/Debug/../src/Projecto.cpp:16: undefined reference to `__gxx_personality_sj0'src\Projecto.o: In function `ZN8ProjectoD1Ev':C:/Users/Francisco/workspace_aeda/estudo_CI1/Debug/../src/Projecto.cpp:16: undefined reference to `__gxx_personality_sj0'src\Projecto.o: In function `ZN8ProjectoD0Ev':C:/Users/Francisco/workspace_aeda/estudo_CI1/Debug/../src/Projecto.cpp:16: undefined reference to `__gxx_personality_sj0'src\Projecto.o: In function `ZN8Projecto4TipoEv':C:/Users/Francisco/workspace_aeda/estudo_CI1/Debug/../src/Projecto.cpp:27: undefined reference to `__gxx_personality_sj0'src\Projecto.o: In function `ZNSt12_Vector_baseISsSaISsEE12_Vector_implD1Ev':C:/strawberry/c/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c  /3.4.5/bits/stl_vector.h:(.text$_ZNSt6vectorISsSaISsEED1Ev[std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::~vector()] 0xc): undefined reference to `__gxx_personality_sj0'src\Projecto.o:C:/strawberry/c/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c  /3.4.5/bits/stl_vector.h:(.text$_ZNSt12_Vector_baseISsSaISsEED2Ev[std::_Vector_base<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::~_Vector_base()] 0xc): more undefined references to `__gxx_personality_sj0' follow/mingw/lib/libstdc  .a(ios_init.o):ios_init.cc:(.text$_ZNSt8ios_base4InitC2Ev 0x719): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ios_init.o):ios_init.cc:(.text$_ZNSt8ios_base4InitC2Ev 0x739): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ios_init.o):ios_init.cc:(.text$_ZNSt8ios_base4InitC2Ev 0x759): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ios_init.o):ios_init.cc:(.text$_ZNSt8ios_base4InitC2Ev 0x779): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ios_init.o):ios_init.cc:(.text$_ZNSt8ios_base4InitC2Ev 0x799): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ios_init.o):ios_init.cc:(.text$_ZNSt8ios_base4InitC2Ev 0x7b9): more undefined references to `_Unwind_Resume' follow/mingw/lib/libstdc  .a(eh_throw.o):eh_throw.cc:(.text$__cxa_throw 0x4e): undefined reference to `_Unwind_RaiseException'/mingw/lib/libstdc  .a(eh_throw.o):eh_throw.cc:(.text$__cxa_rethrow 0x37): undefined reference to `_Unwind_Resume_or_Rethrow'/mingw/lib/libstdc  .a(misc-inst.o):misc-inst.cc:(.text$_ZStrsIwSt11char_traitsIwESaIwEERSt13basic_istreamIT_T0_ES7_RSbIS4_S5_T1_E[std::basic_istream<wchar_t, std::char_traits<wchar_t> >& std::operator>><wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >(std::basic_istream<wchar_t, std::char_traits<wchar_t> >&, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&)] 0x270): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ios.o):ios.cc:(.text$_ZNSt8ios_baseD2Ev 0xd1): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ios.o):ios.cc:(.text$_ZNSt8ios_baseD0Ev 0xd6): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ios.o):ios.cc:(.text$_ZNSt8ios_base13_M_grow_wordsEib 0x126): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ios.o):ios.cc:(.text$_ZNSt8ios_base13_M_grow_wordsEib 0x18e): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ios.o):ios.cc:(.text$_ZNSt8ios_base17_M_call_callbacksENS_5eventE 0x4b): more undefined references to `_Unwind_Resume' follow/mingw/lib/libstdc  .a(eh_personality.o):eh_personality.cc:(.text$__gxx_personality_v0 0xce): undefined reference to `_Unwind_GetIPInfo'/mingw/lib/libstdc  .a(eh_personality.o):eh_personality.cc:(.text$__cxa_call_unexpected 0xd5): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ext-inst.o):ext-inst.cc:(.text$_ZN9__gnu_cxx13stdio_filebufIcSt11char_traitsIcEED1Ev[__gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::~stdio_filebuf()] 0x67): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ext-inst.o):ext-inst.cc:(.text$_ZN9__gnu_cxx13stdio_filebufIcSt11char_traitsIcEED0Ev[__gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::~stdio_filebuf()] 0x6f): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ext-inst.o):ext-inst.cc:(.text$_ZN9__gnu_cxx13stdio_filebufIwSt11char_traitsIwEED1Ev[__gnu_cxx::stdio_filebuf<wchar_t, std::char_traits<wchar_t> >::~stdio_filebuf()] 0x67): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ext-inst.o):ext-inst.cc:(.text$_ZN9__gnu_cxx13stdio_filebufIwSt11char_traitsIwEED0Ev[__gnu_cxx::stdio_filebuf<wchar_t, std::char_traits<wchar_t> >::~stdio_filebuf()] 0x6f): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(ext-inst.o):ext-inst.cc:(.text$_ZN9__gnu_cxx13stdio_filebufIcSt11char_traitsIcEEC2EiSt13_Ios_Openmodej[__gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::stdio_filebuf(int, std::_Ios_Openmode, unsigned int)] 0xb1): more undefined references to `_Unwind_Resume' follow/mingw/lib/libstdc  .a(eh_globals.o):eh_globals.cc:(.text$__cxa_get_globals_fast 0xb): undefined reference to `__emutls_get_address'/mingw/lib/libstdc  .a(eh_globals.o):eh_globals.cc:(.text$__cxa_get_globals 0xb): undefined reference to `__emutls_get_address'/mingw/lib/libstdc  .a(istream.o):istream.cc:(.text$_ZNSi7getlineEPcic 0x26d): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(istream.o):istream.cc:(.text$_ZNSi6ignoreEii 0x2a4): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(istream.o):istream.cc:(.text$_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_ 0x241): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(istream.o):istream.cc:(.text$_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RSbIS4_S5_T1_E 0x2d9): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(istream.o):istream.cc:(.text$_ZSt7getlineIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RSbIS4_S5_T1_ES4_ 0x2a1): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(istream.o):istream.cc:(.text$_ZNSt13basic_istreamIwSt11char_traitsIwEE7getlineEPwiw 0x2a5): more undefined references to `_Unwind_Resume' follow/mingw/lib/libstdc  .a(guard.o):guard.cc:(.text$_ZN12_GLOBAL__N_1L4initEv 0x14): undefined reference to `__gthr_win32_recursive_mutex_init_function'/mingw/lib/libstdc  .a(guard.o):guard.cc:(.text$_ZN9__gnu_cxx17__recursive_mutex6unlockEv[__gnu_cxx::__recursive_mutex::unlock()] 0x15): undefined reference to `__gthr_win32_recursive_mutex_unlock'/mingw/lib/libstdc  .a(guard.o):guard.cc:(.text$__cxa_guard_acquire 0x40): undefined reference to `__gthr_win32_recursive_mutex_lock'/mingw/lib/libstdc  .a(guard.o):guard.cc:(.text$__cxa_guard_acquire 0xe8): undefined reference to `__gthr_win32_recursive_mutex_unlock'/mingw/lib/libstdc  .a(guard.o):guard.cc:(.text$__cxa_guard_acquire 0x12d): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(guard.o):guard.cc:(.text$__cxa_guard_abort 0x21): undefined reference to `__gthr_win32_recursive_mutex_unlock'/mingw/lib/libstdc  .a(guard.o):guard.cc:(.text$__cxa_guard_abort 0x5c): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(guard.o):guard.cc:(.text$__cxa_guard_release 0x29): undefined reference to `__gthr_win32_recursive_mutex_unlock'/mingw/lib/libstdc  .a(guard.o):guard.cc:(.text$__cxa_guard_release 0x64): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(c  locale.o):c  locale.cc:(.text$_ZSt14__convert_to_vIfEvPKcRT_RSt12_Ios_IostateRKPi 0x126): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(c  locale.o):c  locale.cc:(.text$_ZSt14__convert_to_vIdEvPKcRT_RSt12_Ios_IostateRKPi 0x129): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(c  locale.o):c  locale.cc:(.text$_ZSt14__convert_to_vIeEvPKcRT_RSt12_Ios_IostateRKPi 0x151): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(iostream-inst.o):iostream-inst.cc:(.text$_ZNSdC2EPSt15basic_streambufIcSt11char_traitsIcEE[std::basic_iostream<char, std::char_traits<char> >::basic_iostream(std::basic_streambuf<char, std::char_traits<char> >*)] 0x9b): undefined reference to `_Unwind_Resume'/mingw/lib/libstdc  .a(iostream-inst.o):iostream-inst.cc:(.text$_ZNSdC1EPSt15basic_streambufIcSt11char_traitsIcEE[std::basic_iostream<char, std::char_traits<char> >::basic_iostream(std::basic_streambuf<char, std::char_traits<char> >*)] 0xea): more undefined references to `_Unwind_Resume' followcollect2: ld returned 1 exit statusBuild error occurred, build is stoppedTime consumed: 1621  ms. 

编辑2:

这可能与上面的代码无关,因为我编译的所有项目似乎都失败了这些错误(之前编译得很好).

编辑3:
通过删除.metadata解决.无论如何,谢谢你们.

解决方法:

确保使用g编译,而不是使用gcc编译,并确保文件扩展名为.cpp而不是.c

此外,如果您可以编辑帖子并包含您正在使用的g命令,那将是一个很大的帮助.

来源:https://www.icode9.com/content-4-349451.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
忘记WPS工作表当中的撤消密码怎么办?
跨平台C++ MD5类库
Keil C51库函数及学习附录
字符串以及内存操作相关函数
C++:实现split分割字符串
Linux C函数之字符串处理函数
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服