2014-01-08 42 views
1

我有以下代碼:未定義的引用錯誤++

/tmp/cc38RdWw.o: In function `main': 
pocoSender.cpp:(.text+0x4d): undefined reference to `Poco::Net::SocketAddress::SocketAddress(std::string const&, unsigned short)' 
pocoSender.cpp:(.text+0x7d): undefined reference to `Poco::Net::DatagramSocket::DatagramSocket(Poco::Net::SocketAddress const&, bool)' 
pocoSender.cpp:(.text+0x93): undefined reference to `Poco::Timestamp::Timestamp()' 
pocoSender.cpp:(.text+0x11f): undefined reference to `Poco::Timestamp::~Timestamp()' 
pocoSender.cpp:(.text+0x135): undefined reference to `Poco::Net::DatagramSocket::~DatagramSocket()' 
pocoSender.cpp:(.text+0x140): undefined reference to `Poco::Net::SocketAddress::~SocketAddress()' 
pocoSender.cpp:(.text+0x163): undefined reference to `Poco::Net::SocketAddress::~SocketAddress()' 
pocoSender.cpp:(.text+0x1ac): undefined reference to `Poco::Timestamp::~Timestamp()' 
pocoSender.cpp:(.text+0x1ca): undefined reference to `Poco::Net::DatagramSocket::~DatagramSocket()' 
pocoSender.cpp:(.text+0x1d9): undefined reference to `Poco::Net::SocketAddress::~SocketAddress()' 
/tmp/cc38RdWw.o: In function `Poco::DateTimeFormatter::format(Poco::Timestamp const&, std::string const&, int)': 
pocoSender.cpp:(.text._ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi[_ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi]+0x15): undefined reference to `Poco::DateTime::DateTime(Poco::Timestamp const&)' 
pocoSender.cpp:(.text._ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi[_ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi]+0x43): undefined reference to `Poco::DateTime::~DateTime()' 
pocoSender.cpp:(.text._ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi[_ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi]+0x52): undefined reference to `Poco::DateTime::~DateTime()' 
/tmp/cc38RdWw.o: In function `Poco::DateTimeFormatter::format(Poco::DateTime const&, std::string const&, int)': 
pocoSender.cpp:(.text._ZN4Poco17DateTimeFormatter6formatERKNS_8DateTimeERKSsi[_ZN4Poco17DateTimeFormatter6formatERKNS_8DateTimeERKSsi]+0x41): undefined reference to `Poco::DateTimeFormatter::append(std::string&, Poco::DateTime const&, std::string const&, int)' 
collect2: error: ld returned 1 exit status 

我用下面的命令行編譯:

g++ -L/usr/local/lib -lPocoUtil -lPocoFoundation -lPocoNet pocoSender.cpp -o hello 

#include "Poco/Net/DatagramSocket.h" 
    #include "Poco/Net/SocketAddress.h" 
    #include "Poco/Timestamp.h" 
    #include "Poco/DateTimeFormatter.h" 

    int main(int argc, char** argv) 
    { 

    Poco::Net::SocketAddress sa("127.0.0.1", 8080); 

    Poco::Net::DatagramSocket dgs(sa); 
    std::string syslogMsg; 
    Poco::Timestamp now; 
    syslogMsg = Poco::DateTimeFormatter::format(now, 
    "<14>%w %f %H:%M:%S Hello, world!"); 

    return 0; 

} 

和編譯我碰到下面的錯誤後,

請不要將問題標記爲重複,因爲我已經包含使用g ++標誌所需的庫,但我是st生病得到這些錯誤。

+2

庫在命令行上執行源文件和目標文件。 –

+0

也許'-L/usr/local/lib'是指libs不存在的地方。另外可疑的是,如何在鏈接器命令中指定'pocoSender.cpp',它應該在**庫規範之前出現** ... –

+1

[將c代碼鏈接到C++代碼時,g ++鏈接順序依賴關係可能重複] (http://stackoverflow.com/questions/3363398/g-linking-order-dependency-when-linking-c-code-to-c-code) –

回答

0

這意味着編譯器或鏈接器沒有找到這些函數的實現。似乎相應的庫或對象模塊不包含在項目的構建中。