gpt4 book ai didi

c++ - GCC 4.5.2 链接器在使用异常时出现问题 (C++)

转载 作者:行者123 更新时间:2023-11-30 00:58:01 24 4
gpt4 key购买 nike

我尝试编写一个网络服务器。就我而言,它在 Windows 上运行良好。但我想让它也兼容 Unix。而且我认为异常类的遗传性一定有问题。为了更好地理解,仅重要部分:

服务器.cpp

#include <exception>
#include <stdexcept>

#ifdef __unix__
#include "UnixSocket.h"
#elif __WIN32__ || _MSC_VER
#include "WinSocket.h"
#endif

#include "HTTPParser.h"

int main(void) {
try {
socket->socketInit(PORT);
}
catch (exception &e) {
cout << endl << "Exception: " << e.what() << endl;
socket->cleanAll();
}
return 0
}

网络接口(interface).h

class NetInterface : public exception {

private:

public:
virtual void socketInit(const char *port) = 0;
virtual void cleanAll(void) = 0;
virtual void cleanPersCon(void) = 0;
virtual char *akzeptieren(void) = 0;
virtual void empfangen(void) = 0;
virtual void senden(void) = 0;
virtual void *get_in_addr(struct sockaddr *sa) = 0;
virtual string getIncoming(void) = 0;
virtual void setOutcoming(string s) = 0;

virtual ~NetInterface() throw() {};

};

UnixSocket.h

class UnixSocket : virtual public NetInterface { 
private:
[...]
public:
UnixSocket(void);
//kill socket connections
void cleanAll(void);
void cleanPersCon(void);
//SysCalls
void socketInit(const char *port);
char *akzeptieren(void);
void empfangen(void);
void senden(void);
//Getter and Setter
string getIncoming(void);
void setOutcoming(string s);

virtual ~UnixSocket() throw() {};
};

HTTP解析器.h

class HTTPParser : public exception {
private:
[...]

public:
HTTPParser(NetInterface *_socket, string _path);
void parsePacket(void);

virtual ~HTTPParser() throw() {};
};

您可以在那里看到类声明的简短摘要。但是现在 gcc 告诉我这样的事情:

/tmp/cc8DNmKI.o:(.rodata._ZTV10HTTPParser[vtable for HTTPParser]+0x10): undefined reference to `std::exception::what() const'
/tmp/cc8DNmKI.o:(.rodata._ZTV10UnixSocket[vtable for UnixSocket]+0x14): undefined reference to `std::exception::what() const'
/tmp/cc8DNmKI.o:(.rodata._ZTV10UnixSocket[vtable for UnixSocket]+0x78): undefined reference to `std::exception::what() const'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x10): undefined reference to `std::exception::what() const'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x14): undefined reference to `__cxa_pure_virtual'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x18): undefined reference to `__cxa_pure_virtual'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x1c): undefined reference to `__cxa_pure_virtual'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x20): undefined reference to `__cxa_pure_virtual'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x24): undefined reference to `__cxa_pure_virtual'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x28): more undefined references to `__cxa_pure_virtual' follow
/tmp/cc8DNmKI.o:(.rodata._ZTVSt16invalid_argument[vtable for std::invalid_argument]+0x10): undefined reference to `std::logic_error::what() const'
/tmp/cc8DNmKI.o:(.rodata._ZTVSt12domain_error[vtable for std::domain_error]+0x10): undefined reference to `std::logic_error::what() const'
/tmp/cc8DNmKI.o:(.rodata._ZTI10HTTPParser[typeinfo for HTTPParser]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/tmp/cc8DNmKI.o:(.rodata._ZTI10HTTPParser[typeinfo for HTTPParser]+0x8): undefined reference to `typeinfo for std::exception'
/tmp/cc8DNmKI.o:(.rodata._ZTI10UnixSocket[typeinfo for UnixSocket]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/tmp/cc8DNmKI.o:(.rodata._ZTI10UnixSocket[typeinfo for UnixSocket]+0x18): undefined reference to `typeinfo for std::exception'
/tmp/cc8DNmKI.o:(.rodata._ZTI12NetInterface[typeinfo for NetInterface]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/tmp/cc8DNmKI.o:(.rodata._ZTI12NetInterface[typeinfo for NetInterface]+0x8): undefined reference to `typeinfo for std::exception'
/tmp/cc8DNmKI.o:(.rodata._ZTISt16invalid_argument[typeinfo for std::invalid_argument]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/tmp/cc8DNmKI.o:(.rodata._ZTISt16invalid_argument[typeinfo for std::invalid_argument]+0x8): undefined reference to `typeinfo for std::logic_error'
/tmp/cc8DNmKI.o:(.rodata._ZTISt12domain_error[typeinfo for std::domain_error]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/tmp/cc8DNmKI.o:(.rodata._ZTISt12domain_error[typeinfo for std::domain_error]+0x8): undefined reference to `typeinfo for std::logic_error'
/tmp/cc8DNmKI.o:(.eh_frame+0xeb): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

还有更多....

最佳答案

undefined reference to __gxx_personality_v0 链接器消息来看,您似乎正在使用 gcc 进行链接。您需要将 C++ 应用程序与 g++ 链接起来。或者使用 gcc 链接并添加 -lstdc++ 到链接器命令行。

关于c++ - GCC 4.5.2 链接器在使用异常时出现问题 (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7038258/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com