使用muduo-0.9.3的程序编译不过的问题解决

编译报错信息:

/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:302:对‘muduo::Logger::Logger(muduo::Logger::SourceFile, int, muduo::Logger::LogLevel, char const*)’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:302:对‘muduo::LogStream::operator<<(int)’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:302:对‘muduo::Logger::~Logger()’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:288:对‘muduo::Logger::~Logger()’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:293:对‘muduo::Logger::~Logger()’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:302:对‘muduo::Logger::~Logger()’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/build/debug-install/lib/libmuduo_net.a(TcpConnection.cc.o):在函数‘muduo::net::TcpConnection::handleClose()’ 中:
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:310:对‘muduo::Logger::Logger(muduo::Logger::SourceFile, int, muduo::Logger::LogLevel, char const*)’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:310:对‘muduo::LogStream::operator<<(int)’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:310:对‘muduo::LogStream::operator<<(int)’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:310:对‘muduo::Logger::~Logger()’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:310:对‘muduo::Logger::~Logger()’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/build/debug-install/lib/libmuduo_net.a(TcpConnection.cc.o):在函数‘muduo::net::TcpConnection::handleError()’ 中:
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:326:对‘muduo::strerror_tl(int)’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:325:对‘muduo::Logger::Logger(muduo::Logger::SourceFile, int, muduo::Logger::LogLevel)’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:326:对‘muduo::LogStream::operator<<(int)’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:325:对‘muduo::Logger::~Logger()’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/TcpConnection.cc:325:对‘muduo::Logger::~Logger()’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/build/debug-install/lib/libmuduo_net.a(Timer.cc.o):在函数‘muduo::net::Timer::restart(muduo::Timestamp)’中:
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/Timer.cc:24:对‘muduo::Timestamp::invalid()’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/build/debug-install/lib/libmuduo_net.a(EventLoopThread.cc.o):在函数‘muduo::net::EventLoopThread::EventLoopThread(boost::function<void (muduo::net::EventLoop*)> const&)’中:
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/EventLoopThread.cc:25:对‘muduo::Thread::Thread(boost::function<void ()> const&, __gnu_cxx::__versa_string<char, std::char_traits<char>, std::allocator<char>, __gnu_cxx::__sso_string_base> const&)’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/EventLoopThread.cc:25:对‘muduo::Thread::~Thread()’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/build/debug-install/lib/libmuduo_net.a(EventLoopThread.cc.o):在函数‘muduo::net::EventLoopThread::~EventLoopThread()’中:
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/EventLoopThread.cc:33:对‘muduo::Thread::join()’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/EventLoopThread.cc:29:对‘muduo::Thread::~Thread()’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/EventLoopThread.cc:29:对‘muduo::Thread::~Thread()’未定义的引用
/home/xocoder/ThirdParty/muduo-0.9.3/build/debug-install/lib/libmuduo_net.a(EventLoopThread.cc.o):在函数‘muduo::net::EventLoopThread::startLoop()’中:
/home/xocoder/ThirdParty/muduo-0.9.3/muduo/muduo/net/EventLoopThread.cc:39:对‘muduo::Thread::start()’未定义的引用
collect2: 错误: ld 返回 1
make[2]: *** [testMuduo] 错误 1
make[1]: *** [CMakeFiles/testMuduo.dir/all] 错误 2
make: *** [all] 错误 2

这个问题应该是由于链接muduo库顺序的问题导致的,如果先链接muduo_base,再链接muduo_net就会出现这样的编译错误

解决方法:

将CMakeLists中链接库的顺序调换一下即可,先写muduo_net,再写muduo_base

例如:(注:因为muduo使用了线程库中的API,所以也要链接pthread库,否则也会编译不过

TARGET_LINK_LIBRARIES(testMuduo muduo_base muduo_net pthread)


你可能感兴趣的:(使用muduo-0.9.3的程序编译不过的问题解决)