1. 程式人生 > >使用muduo-0.9.3的程式編譯不過的問題解決

使用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)