c++ - g++中的 undefined reference 错误

标签 c++ compilation poco-libraries

我有以下代码:

  #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;

}

编译后出现以下错误:

/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

请不要将问题标记为重复,因为我已经使用 g++ 标志包含了所需的库,但我仍然遇到这些错误。

最佳答案

这意味着编译器或链接器没有找到这些函数的实现。似乎相应的库或目标模块没有包含在项目的构建中。

关于c++ - g++中的 undefined reference 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21001858/

相关文章:

java - Android Studio - 编译 OpenCV 时错误找不到符号类 R

c++ - Opencv 函数只能以 C 代码方式调用,不能以 C++ 方式调用

c++ - 从 64 位整数中提取 32 位

python - 为什么链接器在未在任何地方指定时寻找 python36_d.lib?

c++ - 声明没有大小的数组数据成员

C++/R : RInside in Windows 7 machine

c++ - Poco 可以与 LLVM 标准 C++ 库一起使用吗?

c++ - 我如何使用 openssl 更新过期或创建自签名证书 key any.pem Poco c++

c++ - protected 析构函数的基本原理

c++ - OpenCV FileStorage - 元素之间的错误 : Parsing error (icvYMLParseValue) Missing ,