研二
makefile
最近要重新学makefile了,记录以下每日所学。
- 当可执行文件链接动态库后在执行时,可能会出现这种错误:
test: error while loading shared libraries: libASN1.so: cannot open shared object file: No such file or directory
这种错误的原因是,虽然在编译时已链接了动态库,但在执行程序的时候,可执行文件依然需要寻找动态库。但由于在编译的时候并没有把动态库路径写入可执行文件,因此在这个阶段依然会发生找不到动态库的错误。
解决办法[1]:
test:
gcc -I $(INCLUDE) -c OCSP.c
gcc OCSP.o -Wl,-rpath ./ -L. -o test -lASN1
增加-Wl, -rpath ./
参考文献
[1] -rpath和-rpath-link: https://www.cnblogs.com/Malphite/p/10405465.html