Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ GCC 4.5.2使用异常时链接器出现问题(C+;+;)_C++_Exception_Inheritance_Gcc_Webserver - Fatal编程技术网

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

C++ GCC 4.5.2使用异常时链接器出现问题(C+;+;),c++,exception,inheritance,gcc,webserver,C++,Exception,Inheritance,Gcc,Webserver,我试着写一个Web服务器。就我而言,它与窗户配合使用效果很好。但我想让它也与Unix兼容。我认为这是一个例外类的遗传问题。 为了更好地理解,只需介绍以下重要部分: server.cpp #include <exception> #include <stdexcept> #ifdef __unix__ #include "UnixSocket.h" #elif __WIN32__ || _MSC_VER #include "WinSocket.h" #en

我试着写一个Web服务器。就我而言,它与窗户配合使用效果很好。但我想让它也与Unix兼容。我认为这是一个例外类的遗传问题。 为了更好地理解,只需介绍以下重要部分:

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
}
})

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

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

更重要的是,…

对uuugxx\u personality\u v0的未定义引用判断,
链接器消息看起来您正在链接
gcc
。您需要将C++应用程序与 G++< /C>链接。或者链接到
gcc
,并将
-lstdc++
添加到链接器命令行。

未定义的对uuugxx\u personality\u v0
链接器消息的引用判断,您似乎正在链接到
gcc
。您需要将C++应用程序与 G++< /C>链接。或者使用
gcc
链接,并将
-lstdc++
添加到链接器命令行。

您没有显示相关的代码和编译器调用,但知道
std::exception
有一个未实现的虚拟成员函数
what()
,您需要覆盖该函数,因此,如果您想调用
what()
,请不要抛出赤裸的
std::exception
s


中的任何派生的特定异常都将实现
what()
,并允许您在构造异常对象时存储消息。

您没有显示相关的代码和编译器调用,但知道
std::exception
有一个未实现的虚拟成员函数
what()
您希望覆盖的,所以如果要调用
what()
,请不要抛出裸露的
std::exception
s


中任何派生的特定异常都将实现
what()
并允许您在构建异常对象时存储消息。

您用于链接对象的命令行是什么?可能必须
#包括
,并执行
-lstdc++
链接库。使用
g++
而不是
gcc
编译?是的,我错过了-lstdc++…真丢脸…无论如何谢谢:-)你用来链接对象的命令行是什么?可能必须
#包括
,也必须
-lstdc++
来链接库。使用
g++
编译,而不是
gcc
?是的,我错过了-LSTDC C++ +……我感到羞愧……无论如何,谢谢):“<代码>未定义的引用到yxgxxPuxalItIV0意味着C++运行时没有链接。
/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