2014-03-19 66 views
1

我正在编写一个简单的hello世界程序,以了解如何在Linux中链接共享库。我已成功使用的主要程序编译成与共享库的可执行如下:在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" 它自动查找的其他库自动罚款。

任何人都知道这可能是为什么?

+4

google LD_LIBRARY_PATH – nogard

+0

正是我需要知道的。谢谢 –

回答

1

您的共享图书馆的位置不在链接的搜索路径。您可以通过将库所在的目录添加到LD_LIBRARY_PATH环境变量来确认此操作,然后再次运行ldd。有关详细信息,请参见ld.so(8)手册页。

+0

令人惊叹!感谢您的及时响应! –

相关问题