Error while loading shared libraries: libsystemc-2.3.0.so

时间:2021-11-12 13:26:42

             

安装完成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)