Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared library, makefile. Library path

Tags:

c++

Im trying to link my program to the shared library. Im using a makefile to compile. It looks like this: `

make: sms_out.cpp SMSDispatch.cpp SMSDispatch.h
      g++ -c -fPIC SMSDispatch.cpp -o SMSDispatch.o
      g++ -shared SMSDispatch.o -o libSMSDispatch.so
`     g++ sms_out.cpp -L. -lSMSDispatch -o sms_out

It works fine if I run the program in the command window with:

LD_LIBRARY_PATH="." ./sms_out

But I want to run it with just ./sms_out, can someone help me? Tried to add export LD_LIBRARY_PATH=. to the makefile, but that didnt work, just got the error " error while loading shared libraries: libSMSDispatch.so: cannot open shared object file: No such file or directory" when I try to run the program.

like image 908
Veronic Avatar asked May 12 '26 12:05

Veronic


1 Answers

Another option - provide -rpath options to linker to inform your binary where else search for dynamic objects.

g++ -Wl,-rpath=<path to .so> -o <your binary here> <cpp file name>.cpp
like image 160
Sergei Nikulov Avatar answered May 14 '26 04:05

Sergei Nikulov