1、下载源码
http://sourceforge.net/projects/log4cplus/
2、安装
例如我下载的是2.0.8版本压缩包,需要解压缩
log4cplus-2.0.8.7z
安装解压工具:
apt install p7zip-full
解压:
7z x log4cplus-2.0.8.7z -r -o/home/
配置及编译安装:
(其中make编译过程比较长,需要10多分钟)
cd log4cplus-2.0.8
./configure --prefix=/usr/local
make
make install
3、vscode中配置编译
(1)查看lib路径下是否有对应库:
ls /usr/local/lib
liblog4cplus.so(我这里是动态库)
(2)查看头文件在/usr /local/include/目录下是否有log4cplus
/usr/local/include# ls
google hiredis hv log4cplus
(3)vscode项目中配置使用该lib:
a、CMakeLists.txt中添加:
target_link_libraries(${PROJECT_NAME} liblog4cplus.so)
b、c_cpp_properties.json中添加:
"configurations": [
{
"includePath": [
"xxx"
"/usr/local/include/log4cplus"
],
}
],
c、若编译后链接时出现如下报错,说明需要添加动态库搜索路径:
error while loading shared libraries: liblog4cpp.so.5: cannot open shared object file: No such file
查看其共享库文件安装到了/usr/local/lib,故要把新共享库目录加入到共享库配置文件/etc/ld.so.conf中;
vi /etc/ld.so.conf
#打开该文件后另起一行输入:
/usr/local/lib
#保存后查看
cat /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf
/usr/local/lib
#最后执行如下命令即可解决
ldconfig -v
参考链接:
https://blog.csdn.net/didi_ya/article/details/123148312
https://blog.csdn.net/jinking01/article/details/108678774
https://blog.csdn.net/XZbnhh/article/details/120637777