今天将log4cplus引入自己的程序,由于log4cplus需要线程库的支持,在静态编译的时候加上了-lpthread,但是始终在编译的时候提示找不到线程函数:
[code="plain"]
liblog4cplus.a(socketappender.o): In function `log4cplus::thread::PthreadMutexAttr::set_type(log4cplus::thread::Mutex::Type)':
../include/log4cplus/helpers/syncprims-pthreads.h:80: undefined reference to `pthread_mutexattr_settype'
liblog4cplus.a(socketappender.o): In function `~PthreadMutexAttr':
../include/log4cplus/helpers/syncprims-pthreads.h:58: undefined reference to `pthread_mutexattr_destroy'
liblog4cplus.a(socketappender.o): In function `ManualResetEvent':
../include/log4cplus/helpers/syncprims-pthreads.h:200: undefined reference to `pthread_cond_init'
liblog4cplus.a(socketappender.o): In function `~PthreadMutexAttr':
../include/log4cplus/helpers/syncprims-pthreads.h:58: undefined reference to `pthread_mutexattr_destroy'
liblog4cplus.a(socketappender.o): In function `~ManualResetEvent':
../include/log4cplus/helpers/syncprims-pthreads.h:210: undefined reference to `pthread_cond_destroy'
../include/log4cplus/helpers/syncprims-pthreads.h:210: undefined reference to `pthread_cond_destroy'
liblog4cplus.a(socketappender.o): In function `log4cplus::thread::ManualResetEvent::timed_wait(unsigned long) const':
../include/log4cplus/helpers/syncprims-pthreads.h:272: undefined reference to `pthread_cond_timedwait'
[/code]
于是搜索发现必须在编译的时候加上"-pthread" 才能正常编译通过。
附上g++中-pthread和-lpthread的区别说明文章:
http://blog.chinaunix.net/uid-25909722-id-3026989.html
http://chaoslawful.iteye.com/blog/568602
http://kasicass.blog.163.com/blog/static/395619200992410313759/