[Linux-C++] Ubuntu上程序调用静态库文件

Copy From: http://hi.baidu.com/wang_mouxian/item/2579610c626bc830f3eafcb9

NOTE: 在window 使用visual studio 生成的*.exe文件,如果需要调用到 dll文件,也是需要指定目录。

ubuntu上有一个daemon程序(自己编写的)需要调用到一个libcommunication库文件(也是自己写的),但是Ubuntu一直会显示:

./daemon: error while loading shared libraries: libcommunication.so.1: cannot open shared object file: No such file or directory

 

原因:

Ubuntu上的默认静态库文件调用是在/usr/lib上,如果是其他目录下的库文件则需要特殊指定。

 

假设:libcommunication.so.1的路径在 /home/libcommuncation.so.1

解决方法:

1、在终端上输入:

$export LD_LIBRARY_PATH=/home/libcommuncation.so.1:$LD_LIBRARY_PATH

就可以在该终端上调用daemon程序,不过只限制于该终端有效。

2、在/etc/profile最后一行添加:

export LD_LIBRARY_PATH=/home/libcommuncation.so.1:$LD_LIBRARY_PATH
这样就可以在任何终端上调用daemon程序

posted on 2012-07-21 17:04  applesun0757  阅读(844)  评论(0)    收藏  举报