linux log4cplus 编译,【原创】C++程序静态链接编译log4cplus的问题小记

今天将log4cplus引入自己的程序,由于log4cplus需要线程库的支持,在静态编译的时候加上了-lpthread,但是始终在编译的时候提示找不到线程函数:

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'

于是搜索发现必须在编译的时候加上"-pthread"才能正常编译通过。

附上g++中-pthread和-lpthread的区别说明文章:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值