【发布时间】:2021-10-12 17:18:07
【问题描述】:
我有一个大致相当于这个的项目结构:
>>> ls -R
- whatever
- libfoo.so
- foo.h
- foo.c
- test2.c
- however
- test1.c
libfoo.so 是一个库,test.c 是一个简单的库,现在包含 foo.h 并打印“Hello World!”。
我可以用gcc test1.c -o test -std=c2x -L/dir/to/lib -lfoo 编译
但是当我尝试运行 test 时,我得到:
error while loading shared libraries: liblfoo.so: cannot open shared object file: No such file or directory
我该怎么办?
【问题讨论】:
-
您正在执行
-lfoo,但它抱怨缺少liblfoo.so而不是libfoo.so。哪里有错字? -
@CraigEstey 是的,这是为了展示示例而在重构时打错了字
-
考虑将
-rpath与-L一起使用(或代替) -
您可以查看
readelf -a test输出以查看将搜索哪些目录。 -
@CraigEstey 我运行了该命令但找不到任何目录
标签: c gcc makefile shared-libraries