T
T
Tesla4o2019-01-14 13:58:57
linux
Tesla4o, 2019-01-14 13:58:57

How to add LD_LIBRARY_PATH path in c++ code?

There is a program that installs another program. And it also needs to be done so that it indicates the path to the libraries that come with the program being installed.
I did this:

chdir("path/to/library/");
std::system("export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/path/to/library/");

But he still writes that he does not see these libraries. If you go into this folder and directly from there manually make an export like
export LD_LIBRARY_PATH=$PWD
then everything works fine.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tesla4o, 2019-01-14
@Tesla4o

Thanks for answers! Problem solved easily!
Maybe this will help someone too.

N
none7, 2019-01-14
@none7

Your program is not a sh script. And a couple of lines:

std::system("export myvar=1");
std::system("echo $myvar");

will unexpectedly output an empty string. You either need to set the variable in the same call to system(env LD_LIBRARY_PATH=${LD_LIBRARY_PATH} path/to/app) or manually change the variables of your program (getenv/setenv).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question