Error while loading shared libraries: libsystemc-2.3.0.so

             

安装完成systemC-2.3.0 后自己编了一个helloorld的小程序。

[root@localhost hello]# make
g++ -o hello hello.cpp -L/usr/systemc/lib-linux -I/usr/systemc/include -lsystemc
[root@localhost hello]# ./hello
./hello: error while loading shared libraries: libsystemc-2.3.0.so: cannot open shared object file: No such file or directory

如上显示:编译ok,但是执行不了。显示不能找到库文件。

打开systemc的目录看到该库存在的。

思考原因:在实际执行时不能加载库文件。

以下是网上找到的方法。最后是我的Makefile内容。解决问题。


This is a environment setting issue for dynamic linking, because the shared library is installed outside of the system default library directories. When you execute the binary, the loader failed to find libsystemc-2.3.0.so.

Two solutions.

setting your LD_LIBRARY_PATH.

export LD_LIBRARY_PATH=/usr/local/systemc-2.3.0/lib-linux64:$LD_LIBRARY_PATH

or, if your default LD_LIBRARY_PATH is empty

export LD_LIBRARY_PATH=/usr/local/systemc-2.3.0/lib-linux64

adding rpath to the executable when linking the binary. It adds an entry to the binary and hints the loader to search additional path.

g++ -o TestSystemC ...your c++ files... -L/usr/local/systemc-2.3.0/lib-linux64 -lsystemc-2.3.0 -Wl,-rpath,/usr/local/systemc-2.3.0/lib-linux64


我的Makefile:

LIB_DIR=-L/usr/systemc/lib-linux                                                                                                                                                        
INC_DIR=-I/usr/systemc/include                                                                                                                                                       
LIB=-lsystemc -Wl,-rpath,/usr/systemc/lib-linux                                                                                                                                                                                                                                                                                                                                                                    
App=hello                                                                                                                                                                                                                                                         
all:                                                                                                                                                                                                             
        g++ -o $(App) $(App).cpp $(LIB_DIR) $(INC_DIR) $(LIB)                                                                                                                                                                                                                                                       CLEAN:                                                                                                                                                                                                         
        RM -RF $(App)   


  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值