我正在Ubuntu 14.04 x64上构建一个守护程序应用程序,我收到一个链接器错误:
undefined reference to symbol 'pthread_rwlock_wrlock@@GLIBC_2.2.5'
代码是
#include <Poco/RWLock.h>
class DatabaseHandler
{
public:
typedef std::shared_ptr<DatabaseHandler> Ptr;
DatabaseHandler() {};
virtual ~DatabaseHandler() {};
virtual bool Connect(const STRING& connstring);
bool Disconnect();
BOOL IsConnected() {
return (m_pSession && m_pSession->isConnected());
}
protected:
std::unique_ptr<Poco::Data::Session> m_pSession;
Poco::RWLock m_write_lock;
};
class FADatabaseHandler : public DatabaseHandler
{
public:
EDBReturnValues UpdateHouse(TFAData& data);
private:
BOOL HouseExists(const UINT HouseId);
};
并实施..
EDBReturnValues FADatabaseHandler::UpdateHouse(TFAData& data)
{
Poco::ScopedWriteRWLock lock(m_write_lock);
.....
}
此文件的编译器命令行是
g++ -Wall -fexceptions -std=c++11 -g -lrt -lm -lpthread -DPOCO_STATIC -DPOCO_NO_AUTOMATIC_LIBS -DUSING_POCO_LIB -DBUILD_AS_SERVER -I/usr/local/mysql/include -c /home/daniele/src/TBServer/FADatabaseHandler.cpp -o obj/Debug/FADatabaseHandler.o
如果我注释了RWLock.h include,m_write_lock和ScopedWriteRWLock调用,我会收到错误:
/usr/bin/ld: /usr/local/lib/libPocoFoundationd.a(TextEncoding.o): undefined reference to symbol 'pthread_rwlock_wrlock@@GLIBC_2.2.5'
我哪里错了?
问候。
答案 0 :(得分:2)
如果你使用CMake,你可以这样做:
...
find_package(Threads)
...
target_link_libraries(
...
${CMAKE_THREAD_LIBS_INIT}
)