g ++在我的项目的两行中发出了一个模糊的错误undefined reference to '__gxx_personality_sj0'
。在这种情况下,这意味着什么?我google了很多,发现这通常与在C ++中包含C代码或类似的东西有关,这不是我想要的。 (我知道代码质量不高,但应该编译,我相信)。
Projecto.cpp
#include "Projecto.h"
#include <iostream>
#include <iomanip>
#include <string>
Projecto::~Projecto() {} //THIS LINE GETS THAT ERROR
void 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_ */
感谢您阅读此内容!
编辑:
我正在使用带有mingw工具链的Eclipse。我最近安装了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.o
Warning: .drectve `-aligncomm:___mingw_gMTRemoveKeyDtor,2 ' unrecognized
Warning: .drectve `-aligncomm:___mingw_gMTKeyDtor,2 ' unrecognized
Warning: .drectve `-aligncomm:___mingw_usemthread_dll,2' unrecognized
Warning: .drectve `-aligncomm:___hexdig_D2A,2' unrecognized
src\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' follow
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 1621 ms.
编辑2:
这可能与上面的代码无关,因为我编译的所有项目似乎都失败了这些错误(之前编译得很好)。
编辑3:
通过删除.metadata
解决。无论如何,谢谢你们。
答案 0 :(得分:5)
确保使用g ++编译,而不是使用gcc编译,并确保文件扩展名为.cpp而不是.c
此外,如果您可以编辑帖子并包含您正在使用的g ++命令,那将是一个很大的帮助。
答案 1 :(得分:2)
您是否一直使用相同的g++
进行编译和链接?
答案 2 :(得分:2)
您清理了项目?也许以前的.o文件是用另一个版本的lib构建的。
答案 3 :(得分:0)
使用g ++作为链接器或链接-lstdc ++