QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1142|回复: 1

关于连接库的问题

[复制链接]
发表于 2006-5-3 17:21:47 | 显示全部楼层 |阅读模式
我创建了一个连接库,叫libclass.so,我在其他程序中想使用这个库,我的方法是:
g++ -s -shared -o main main.cpp -lclass -L.

共享库文件与main.cpp在同一个目录下,编译没有问题,但是运行的时候总是提示 error loading shared libraries: libclass.so connot open shared object file: no such file or directory
发表于 2006-5-3 17:48:23 | 显示全部楼层
从"Advanced Linux Programming"上抄来的:

When you link a program with a shared library, the linker does not put the full path to the shared library in the resulting executable. Instead, it places only the name of the shared library. When the program is actually run, the system searches for the shared library and loads it. The system searches only /lib and /usr/lib, by default. If a shared library that is linked into your program is installed outside those directories, it will not be found, and the system will refuse to run the program.

One solution to this problem is to use the -Wl, -rpath option when linking the program.
Another solution to this problem is to set the LD_LIBRARY_PATH environment variable when running the program.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-2 10:27 , Processed in 0.037071 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表