无法打开共享对象文件:存在文件时没有此类文件或目录错误
cannot open shared object file: No such file or directory error while there is file
我尝试创建共享库并用这个库编译我的main.c
我关注这个网站:http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html
我给出了这些命令:
gcc -fPIC -c *.c
gcc -shared -Wl,-rpath,/opt/lib -Wl,-soname,libctest.so.1 -o libctest.so.1.0 *.o
sudo mv libctest.so.1.0 /opt/lib
sudo ln -sf /opt/lib/libctest.so.1.0 /opt/lib/libctest.so
sudo ln -sf /opt/lib/libctest.so.1.0 /opt/lib/libctest.so.1
gcc -Wall -L/opt/lib main.c -lctest -o prog
命令没有错误。当我执行二进制文件 ./prog
它给出 ./prog: error while loading shared libraries: libctest.so.1: cannot open shared object file: No such file or directory
但是 libctest.so.1
在 /opt/lib
lrwxrwxrwx 1 root root 24 Aug 18 17:06 libctest.so -> /opt/lib/libctest.so.1.0
lrwxrwxrwx 1 root root 24 Aug 18 17:06 libctest.so.1 -> /opt/lib/libctest.so.1.0
-rwxr-xr-x 1 user user 7064 Aug 18 17:05 libctest.so.1.0
另外 ldd prog
是
linux-vdso.so.1 (0x00007ffe0f559000)
libctest.so.1 => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcd27fc6000)
/lib64/ld-linux-x86-64.so.2 (0x00007fcd28371000)
怎么了?
我用了debian 8.5
和gcc 4.9.2
尝试将 /opt/lib 添加到 LD_LIBRARY_PATH,如下所示;
LD_LIBRARY_PATH=/opt/lib
GCC 的 ld
命令有一个 --rpath
选项可以解决您的问题:
-rpath=dir
Add a directory to the runtime library search path.
您应该在编译 prog
时通过 -wl
选项将已编译库的位置添加到 GCC 的命令行:
-Wl,option
Pass option as an option to the linker. If option contains commas,
it is split into multiple options at the commas.
所以你的搜索路径已经包含了/opt/lib
因为库的原始创建:
-Wl,-rpath,/opt/lib
第二次编译时,将libctest.so.1.0
的位置添加为另一个rpath
,无需移动文件即可找到:
gcc -Wall -L/opt/lib main.c -lctest -Wl,-rpath,/you/dir/name -o prog
我认为你最初的努力失败了,因为链接器包含了一个硬路径到你原来的输出目录,然后你从它下面移动了库。
我和iccxml
有同样的问题
iccToXml profile.icc profile.xml
当我通过上面的代码将 *.icc 转换为 *.xml 时,我收到了相同的消息:无法打开共享对象文件:没有这样的文件或目录,详细信息:
iccToXml: error while loading shared libraries: libIccXML.so.2: cannot open shared object file: No such file or directory
我在转换之前使用这个命令解决了
export LD_LIBRARY_PATH="/usr/local/lib"
您可以将“/usr/local/lib”替换为您想要的应用程序文件路径。
希望对你有所帮助。
我尝试创建共享库并用这个库编译我的main.c
我关注这个网站:http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html
我给出了这些命令:
gcc -fPIC -c *.c
gcc -shared -Wl,-rpath,/opt/lib -Wl,-soname,libctest.so.1 -o libctest.so.1.0 *.o
sudo mv libctest.so.1.0 /opt/lib
sudo ln -sf /opt/lib/libctest.so.1.0 /opt/lib/libctest.so
sudo ln -sf /opt/lib/libctest.so.1.0 /opt/lib/libctest.so.1
gcc -Wall -L/opt/lib main.c -lctest -o prog
命令没有错误。当我执行二进制文件 ./prog
它给出 ./prog: error while loading shared libraries: libctest.so.1: cannot open shared object file: No such file or directory
但是 libctest.so.1
在 /opt/lib
lrwxrwxrwx 1 root root 24 Aug 18 17:06 libctest.so -> /opt/lib/libctest.so.1.0
lrwxrwxrwx 1 root root 24 Aug 18 17:06 libctest.so.1 -> /opt/lib/libctest.so.1.0
-rwxr-xr-x 1 user user 7064 Aug 18 17:05 libctest.so.1.0
另外 ldd prog
是
linux-vdso.so.1 (0x00007ffe0f559000)
libctest.so.1 => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcd27fc6000)
/lib64/ld-linux-x86-64.so.2 (0x00007fcd28371000)
怎么了?
我用了debian 8.5
和gcc 4.9.2
尝试将 /opt/lib 添加到 LD_LIBRARY_PATH,如下所示;
LD_LIBRARY_PATH=/opt/lib
GCC 的 ld
命令有一个 --rpath
选项可以解决您的问题:
-rpath=dir
Add a directory to the runtime library search path.
您应该在编译 prog
时通过 -wl
选项将已编译库的位置添加到 GCC 的命令行:
-Wl,option
Pass option as an option to the linker. If option contains commas,
it is split into multiple options at the commas.
所以你的搜索路径已经包含了/opt/lib
因为库的原始创建:
-Wl,-rpath,/opt/lib
第二次编译时,将libctest.so.1.0
的位置添加为另一个rpath
,无需移动文件即可找到:
gcc -Wall -L/opt/lib main.c -lctest -Wl,-rpath,/you/dir/name -o prog
我认为你最初的努力失败了,因为链接器包含了一个硬路径到你原来的输出目录,然后你从它下面移动了库。
我和iccxml
有同样的问题iccToXml profile.icc profile.xml
当我通过上面的代码将 *.icc 转换为 *.xml 时,我收到了相同的消息:无法打开共享对象文件:没有这样的文件或目录,详细信息:
iccToXml: error while loading shared libraries: libIccXML.so.2: cannot open shared object file: No such file or directory
我在转换之前使用这个命令解决了
export LD_LIBRARY_PATH="/usr/local/lib"
您可以将“/usr/local/lib”替换为您想要的应用程序文件路径。
希望对你有所帮助。