Issue
I am a new user to Linux and I am trying to install systemc-2.3.0
library on my machine (Fedora 16). I have followed every instructions very carefully, mentioned in the INSTALL file of the library but I am getting an error when I am trying to run a simple program using ECLIPSE. I have linked all the libraries correctly in ECLIPSE but still I am getting an error.
The program is as follows:
#include <systemc.h>
using namespace std;
int sc_main(int argc, char * argv[])
{
cout << "hello world" << endl;
for(int i=0; i<argc; i++)
cout << argv[i] << " ";
cout << endl;
return 0;
}
And the error output is:
/home/vivek/workspace/TestSystemC/Debug/TestSystemC: error while loading shared libraries: libsystemc-2.3.0.so: cannot open shared object file: No such file or directory
Any help will be highly appreciated. Please explain your suggestions in an elaborative manner (step by step) as I am not an Linux expert.
Thank you.
Solution
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
Answered By - jclin
Answer Checked By - Cary Denson (JavaFixing Admin)