GCC 4.5.2链接器问题使用异常时的问题(C ++) [英] GCC 4.5.2 Linker gots Problem while using Exceptions (C++)

查看:394
本文介绍了GCC 4.5.2链接器问题使用异常时的问题(C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试写一个网络服务器。就我而言,它工作安静良好与Windows。但我想让它也与Unix兼容。我认为有一个问题的遗传f的异常类。
为了更好地理解,只是重要的部分:

I try to write a webserver. As far as I am, it works quiet good with Windows. But I want to make it also Unix compatible. And I think there has to be a problem with the heredity f the exception class. For better understanding, just the important parts:

server.cpp

server.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
}

NetInterface.h



NetInterface.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

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() {};
};

HTTPParser.h

HTTPParser.h

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

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

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

您可以在这里找到类声明的简短摘要。
但现在gcc告诉我这样的东西:

There you can se a short summary of the class declarations. But now the gcc tells me something like this:

/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


$ b b

甚至更多....

and even more....

推荐答案

判断未定义的引用__gxx_personality_v0 链接器消息,它看起来像你正在链接 gcc 。您需要链接C ++应用程序与 g ++ 。或链接到 gcc ,并将 -lstdc ++ 添加到链接器命令行。

Judging from undefined reference to __gxx_personality_v0 linker message it looks like you are linking with gcc. You need to link C++ applications with g++. Or link with gcc and add -lstdc++ to the linker command line.

这篇关于GCC 4.5.2链接器问题使用异常时的问题(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆