• 9394阅读
  • 8回复

linux 下怎么才能指定so文件的位置??是不是库文件编译好都要放在/usr/lib下 [复制链接]

上一主题 下一主题
离线leehus
 

只看楼主 倒序阅读 楼主  发表于: 2009-12-31
main.pro文件中指定了:LIBS+=-L../lib -lgood
可是执行的时候还是报:error while loading shared lib的错误
我把so和so.1都拷到执行文件的文件夹中也报同样的错误
请帮忙解答,谢谢。



是不是库文件编译好都要放在/usr/lib下?能不能在编译的时候指定一个文件夹呢?

解决办法:我在etc/ld.so.conf.d中建了一个自己的配置文件,指定了库文件的路径

但是每次编译后都要sudo ldconfig  一次才行,不然还是找不到

不知TX们,在开发的时候是怎么解决这种  查找自己的库的文件  的问题的,如果有好办法麻烦告诉我

小弟我第一天接触学习在linux 下QT编程,以前没玩过linux,还请大家多多指教!
[ 此帖被leehus在2009-12-31 13:31重新编辑 ]
离线dbzhang800

只看该作者 1楼 发表于: 2009-12-31
Locating Libraries at Runtime
Once a program has been linked to use shared libraries, it must be able to find the shared
library when it runs. The libraries are located by name, not by directory, so it is possible
to link the program against one copy of the library and run it using another. This can, of course, cause problems if yous witch from one version of the library to another without updating the program—which is the reason most libraries include a version number as part of the name (for example, libm.so.6 or libutil-2.2.4.so).
Whenever a program loads and prepares to run, the shared libraries it needs are sought in the following places:
■ Each of the directories listed in the colon-separated list in the environment variable LD_LIBRARY_PATH
■ The list of libraries found in the file /etc/ld.so.cache, which is maintained by the ldconfig utility
■ The directory /lib
■ The directory /usr/lib
If you want to find out which libraries are being loaded and used by a specific application, you can use the ldd utility described later in this chapter.
Another environment variable, LD_PRELOAD, can contain a list of shared library
names (separated by spaces, tabs, or newlines) that will be preloaded before any other library searching takes place. In this way, you can override the functions that would normally be loaded from a shared library. For security reasons, some limitations are imposed on this technique for setuid programs.
离线leehus

只看该作者 2楼 发表于: 2009-12-31
多谢楼上的,可是我已经在pro文件指定了lib的位置了,而且库文件的名字也是对的,他找libgood.so.1,我的lib文件夹下有这个文件啊,为什么还是没找到呢???
离线dbzhang800

只看该作者 3楼 发表于: 2009-12-31
引用第2楼leehus于2009-12-31 10:37发表的  :
多谢楼上的,可是我已经在pro文件指定了lib的位置了,而且库文件的名字也是对的,他找libgood.so.1,我的lib文件夹下有这个文件啊,为什么还是没找到呢???


我知道你 pro 内指定链接选项了,所以你的链接也不存在问题,我也没提
How to Locating Libraries at Link Time

你前面都说了,你是运行时找不到库,而不是链接时
所以不妨认真看看前面的帖子
离线20044454
只看该作者 4楼 发表于: 2009-12-31
在.pro文件里面加CONFIG +=plugin 编译后只生成.so文件 不会有.so.1  也不需要了.so .1了,

把生成的.so  cp 到/usr/lib/目录下 应该就可以了
让我做一个Qt的大牛!!!!
离线leehus

只看该作者 5楼 发表于: 2009-12-31
OK,也就是说编译链接的时候找到了库文件,运行的时候还是要到默认的系统库文件夹去找库文件?对吧

如果是这样,是不是我export一次lD_LIBRARY_PATH就行了,然后每次执行程序的时候就能找到了?

有没有办法在编译的时候就指定运行时的库文件的位置呢??
离线蛮蛮
只看该作者 6楼 发表于: 2009-12-31
运行时应该是先在当前目录找,然后到系统库文件目录下找
蛮蛮工作室
离线抠涕
只看该作者 7楼 发表于: 2010-01-02
不会在当前目录找。
离线benbenmajia

只看该作者 8楼 发表于: 2010-01-11
看你设置的路径是什么了,如果是./就是在当前目录下找
安然.....
快速回复
限100 字节
 
上一个 下一个