简体   繁体   English

Linux运行时链接器错误

[英]Linux runtime linker error

I'm working though the First Steps tutorial on the POCO Project site, and I've successfully built the library (Debian Linux, 2.6.26, gcc 4.3.2) under my home directory 我正在POCO项目网站上的第一步教程,我已经在我的主目录下成功构建了库(Debian Linux,2.6.26,gcc 4.3.2)

~/Development/POCO

with the shared libraries located in 共享库位于

~/Development/POCO/lib/Linux/x86_64/lib

My problem is that any application I build that depends on these libraries can only be run from the shared library directory. 我的问题是,我构建的依赖于这些库的任何应用程序只能从共享库目录运行。

~/Development/POCO/lib/Linux/x86_64$ ldd ~/Development/Cloud/DateTimeSample/bin/Linux/x86_64/DateTime
        linux-vdso.so.1 =>  (0x00007fffe69fe000)
        libPocoFoundation.so.6 (0x00007fa8de44f000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x00007fa8de233000)
        libdl.so.2 => /lib/libdl.so.2 (0x00007fa8de02f000)
        librt.so.1 => /lib/librt.so.1 (0x00007fa8dde26000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fa8ddb1a000)
        libm.so.6 => /lib/libm.so.6 (0x00007fa8dd897000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fa8dd680000)
        libc.so.6 => /lib/libc.so.6 (0x00007fa8dd32d000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fa8de7e0000)

And running DateTime from this directory would work as you would expect. 从这个目录运行DateTime可以正常工作。 However 然而

~/Development/Cloud/DateTimeSample/bin/Linux/x86_64$ ldd DateTime
        linux-vdso.so.1 =>  (0x00007fff24dfe000)
        libPocoFoundation.so.6 => not found
        libpthread.so.0 => /lib/libpthread.so.0 (0x00007ffc1c7dd000)
        libdl.so.2 => /lib/libdl.so.2 (0x00007ffc1c5d9000)
        librt.so.1 => /lib/librt.so.1 (0x00007ffc1c3d0000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007ffc1c0c4000)
        libm.so.6 => /lib/libm.so.6 (0x00007ffc1be41000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007ffc1bc2a000)
        libc.so.6 => /lib/libc.so.6 (0x00007ffc1b8d7000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ffc1c9f9000)

so running the executable from any other directory results in 所以从任何其他目录运行可执行文件导致

error while loading shared libraries: libPocoFoundation.so.6: cannot open shared object file: No such file or directory

Looking at the output from the make process, the directory is correctly specified 查看make进程的输出,正确指定了目录

g++ [blah] -L/home/npalko/Development/POCO/lib/Linux/x86_64 
           -lPocoFoundation

I've tried setting 我试过设定

LD_LIBRARY_PATH
to
 /home/npalko/Development/POCO/lib/Linux/x86_64 /家庭/ npalko /开发/ POCO / lib中/ Linux的/ x86_64的 
, but it has not changed anything. ,但它没有改变任何东西。 Any help would be greatly appreciated! 任何帮助将不胜感激!

If you don't want to have to deal with the LD_LIBRARY_PATH variable, you can add the linker -rpath option to the gcc command line. 如果您不想处理LD_LIBRARY_PATH变量,可以将链接器-rpath选项添加到gcc命令行。 In your case, this would be: 在您的情况下,这将是:

gcc ... -Wl,-rpath=/home/npalko/Development/POCO/lib/Linux/x86_64

This effectively hardcodes that path in the executable, so it may or may not be suitable for your purposes. 这有效地硬编码了可执行文件中的路径,因此它可能适用于您的目的,也可能不适用。

This fails? 这失败了?

LD_LIBRARY_PATH=/home/npalko/Development/POCO/lib/Linux/x86_64 ~/Development/Cloud/DateTimeSample/bin/Linux/x86_64/DateTime

Just thought you may not be setting LD_LIBRARY_PATH properly 只是想你可能没有正确设置LD_LIBRARY_PATH

And this? 和这个?

ls -alh /home/npalko/Development/POCO/lib/Linux/x86_64/libPocoFoundation.so

If both fail I can't see a reason. 如果两者都失败了,我看不出原因。

You must specify to the linker the path of your library 您必须向链接器指定库的路径

g++ [blah] -Wl,-rpath=/home/npalko/Development/POCO/lib/Linux/x86_64

-Wl means your pass an option to the linker -Wl表示您传递链接器的选项

-rpath is the linker option -rpath是链接器选项

Add a directory to the runtime library search path. 将目录添加到运行时库搜索路径。 This is used when linking an ELF executable with shared objects. 将ELF可执行文件与共享对象链接时使用此方法。 All -rpath arguments are concatenated and passed to the runtime linker, which uses them to locate shared objects at runtime. 所有-rpath参数都连接在一起并传递给运行时链接程序,后者使用它们在运行时查找共享对象。 The -rpath option is also used when locating shared objects which are needed by shared objects explicitly included in the link; 在定位链接中明确包含的共享对象所需的共享对象时,也会使用-rpath选项;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM