在linux中使用共享库执行二进制文件
Executing a binary with a shared library in linux
我正在制作一个简单的hello world程序来学习如何在linux中链接共享库。我已经设法将主程序与共享库一起编译成可执行文件,使用以下命令:
g++ -fPIC -c lab2_hello_main.cpp <--create position independent objects
g++ -fPIC -c lab2_hello_sub.cpp
g++ -fPIC -shared -Wl,-soname=libfuncs.so.1.0 *.o -o libfuncs.so.1.0 -lc <--make the shared library
ln -s libfuncs.so.1.0 libfuncs.so <-- soft links for compiling and running
ln -s libfuncs.so.1.0 libfuncs.so.1
g++ -o hello_dyn lab2_hello_main.cpp -L/mypath -lfuncs <-- Linking the library to main
当我在hello_dyn上执行ldd时,我得到一个输出,说明无法找到库:
"libfuncs.so.1.0 => not found"
它自动查找的其他库没有问题。
有谁知道这是为什么吗?
共享库的位置不在链接器的搜索路径中。您可以通过将库所在的目录添加到LD_LIBRARY_PATH
环境变量中来确认这一点,然后再次运行ldd
。详细信息请参见ld.so(8)手册页。
相关文章:
- 如何忽略某些二进制文件的执行?
- -bash:/a.out:无法执行二进制文件:Exec格式错误
- c ++:如何为每个特征制作特定的二进制文件(可执行文件)?
- 我有一个预处理的 C/C++ 源文件 (cacti.i).如何从这个 .i 文件生成可执行二进制文件,以便我可以像 ./
- 如果在执行过程中替换二进制文件,"const"数组是否驻留在内存中?
- 如何告诉 clang 将调试符号放入可执行二进制文件中
- Docker Centos,无法执行二进制文件
- bash:./main:无法执行二进制文件:Exec格式错误
- 如何直接从分配的内存中执行mmaped二进制文件/代码
- 在运行时动态更新二进制文件(可执行文件)而不停止的任何类型的方法
- 无法使用字符串中的命令使用 execlp() 执行二进制文件
- 从没有外壳的C++执行二进制文件
- 从 Web UI 访问C++编译的可执行二进制文件
- bash:即使二进制和Linux是64位的,也无法执行二进制文件:Exec格式错误
- AWS:无法执行二进制文件
- 从内存执行二进制文件
- PHP - 无法执行 c++ 二进制文件?
- 如何制作不依赖于 .so 文件的可执行二进制文件
- 使用apache thrift通过exec执行二进制文件
- 在linux中使用共享库执行二进制文件