redhat linux 下安装 log4cpp

本文详细介绍了如何使用root用户安装log4cpp版本log4cpp-0.3.5rc3,包括解包、配置、修复源码bug、编译、安装过程,以及环境变量设置和最终验证步骤。
  • 以 root 用户安装 log4cpp,采用版本是
log4cpp-0.3.5rc3.tar.gz
  • 解包文件
cd /usr/local tar zxvf log4cpp-0.3.5rc3.tar.gz
  • 进入源码目录,并运行配置命令,增加 pthread 支持
cd log4cpp-0.3.5rc3 ./configure --with-pthreads
  • 配置完成后,需要修改2个地方(这是源码的 bug)
第一处:代码中多了一个分号
vi include/log4cpp/Manipulator.hh

删除29行最后的分号

第二处:打印线程号,线程id 是无符号长整型

vi src/PThreads.cpp
::sprintf(buffer, "%ld", pthread_self());
改为
::sprintf(buffer, "%lu", pthread_self());
  • 现在可以开始编译和安装
make make install
  • 安装完成后,include 文件 和 lib 文件分别被安装到以下目录
/usr/local/include /usr/local/lib
  • 因此在编写代码时,可以这样包括 log4cpp 的头文件,例如
#include <log4cpp/Category.hh>
  • 最后是环境变量处理,需要在 LD_LIBRARY_PATH 中增加 log4cpp 库文件目录
vi /etc/profile.d/log4cpp.sh

内容为

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib export LD_LIBRARY_PATH

保存好文件后,增加文件的可执行权限

chmod a+x /etc/profile.d/log4cpp.sh

好了,退出重登录,大功告成。

/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: /opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/libstdc++_nonshared.a(thread48.o): in function `std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)())': (.text._ZNSt6thread15_M_start_threadESt10unique_ptrINS_6_StateESt14default_deleteIS1_EEPFvvE+0x11): undefined reference to `pthread_create' /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: /opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/libstdc++_nonshared.a(thread48.o): in function `std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>, void (*)())': (.text._ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFvvE+0x60): undefined reference to `pthread_create' /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: test.o: in function `std::thread::thread<ThreadPool::ThreadPool(int)::{lambda()#1}, , void>(ThreadPool::ThreadPool(int)::{lambda()#1}&&)': test.cpp:(.text._ZNSt6threadC2IZN10ThreadPoolC4EiEUlvE_JEvEEOT_DpOT0_[_ZNSt6threadC5IZN10ThreadPoolC4EiEUlvE_JEvEEOT_DpOT0_]+0x21): undefined reference to `pthread_create' /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: log.o: in function `std::thread::thread<void (&)(), , void>(void (&)())': log.cpp:(.text._ZNSt6threadC2IRFvvEJEvEEOT_DpOT0_[_ZNSt6threadC5IRFvvEJEvEEOT_DpOT0_]+0x21): undefined reference to `pthread_create' /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: sqlconnpool.o: in function `SqlConnPool::GetConn()': sqlconnpool.cpp:(.text+0x13d): undefined reference to `sem_wait' /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: sqlconnpool.o: in function `SqlConnPool::FreeConn(MYSQL*)': sqlconnpool.cpp:(.text+0x207): undefined reference to `sem_post' /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: sqlconnpool.o: in function `SqlConnPool::Init(char const*, int, char const*, char const*, char const*, int)': sqlconnpool.cpp:(.text+0x2e7): undefined reference to `mysql_init' /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: sqlconnpool.cpp:(.text+0x3a5): undefined reference to `mysql_real_connect' /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: sqlconnpool.cpp:(.text+0x45d): undefined reference to `sem_init' /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: sqlconnpool.o: in function `SqlConnPool::ClosePool()': sqlconnpool.cpp:(.text+0x4ce): undefined reference to `mysql_close' /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: sqlconnpool.cpp:(.text+0x4d5): undefined reference to `mysql_server_end' collect2: error: ld returned 1 exit status 分析一下每个都是什么错误
最新发布
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值