linux 设置 包含头文件路径 和 动态库链接路径
简介
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20C/C++程序在linux下被编译和连接时,GCC/G++会查找系统默认的include和link的路径,以及自己在编译命令中指定的路径.
而我们自己安装的第三方软件包后,如果指定了路径,我们如何加入到系统环境变量中?
//include头文件路径
除了默认的"/usr/include","/usr/local/include"等include路径外,还可以通过设置环境变量来添加系统include的路径:
* C
export C_INCLUDE_PATH=XXXX:$C_INCLUDE_PATH
* CPP
export CPLUS_INCLUDE_PATH=XXX:$CPLUS_INCLUDE_PATH
//动态库链接库文件路径
一般Linux系统把"/lib","/usr/lib","/usr/local/lib"作为默认的库搜索路径,所以使用这几个目录中的链接库文件可直接被搜索到.还可以通过设置环境变量来添加到搜索中
方法一:
* 动态链接库搜索路径:
export LD_LIBRARY_PATH=XXX:$LD_LIBRARY_PATH
* 静态链接库搜索路径:
export LIBRARY_PATH=XXX:$LIBRARY_PATH
方法二:
echo "/path/to/app/lib" | tee /etc/ld.so.conf.d/app.conf
ldconfig实例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29[root@smallasa build]# pip install pygit2
报错信息:
src/types.h:36:2: error: #error You need a compatible libgit2 version (v0.26.x)
解决方法:
[root@smallasa app]# wget https://codeload.github.com/libgit2/libgit2/tar.gz/v0.26.0
[root@smallasa app]# tar xzf v0.26.
[root@smallasa app]# cd libgit2-0.26.0/
[root@smallasa libgit2-0.26.0]# mkdir build && cd build
[root@smallasa build]# cmake ..
[root@smallasa build]# cmake --build .
[root@smallasa build]# make test
[root@smallasa build]# ./libgit2_clar
[root@smallasa build]# cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/libgit2
[root@smallasa build]# cmake --build . --target install
设置头文件路径 和 动态库链接路径:
[root@smallasa build]# echo 'export C_INCLUDE_PATH=/usr/local/libgit2/include:$C_INCLUDE_PATH' |tee /etc/profile.d/libgit2.sh
[root@smallasa build]# echo 'export CPLUS_INCLUDE_PATH=/usr/local/libgit2/include:$CPLUS_INCLUDE_PATH' |tee -a /etc/profile.d/libgit2.sh
[root@smallasa build]# echo 'export LD_LIBRARY_PATH=/usr/local/libgit2/lib:$LD_LIBRARY_PATH' | tee -a /etc/profile.d/libgit2.sh
[root@smallasa build]# echo 'export LIBRARY_PATH=/usr/local/libgit2/lib:$LIBRARY_PATH' | tee -a /etc/profile.d/libgit2.sh
[root@smallasa build]# source /etc/profile
提示: 如果不指定头文件路径和动态链接库路径,会报错如下:
src/blob.h:33:18: fatal error: git2.h: No such file or directory
成功安装:
[root@smallasa build]# pip install pygit2
Successfully installed pygit2-0.26.0