C ++: How to link the library located in my project folder?

I use Linux and Eclipse.
I want to use the library ( Box2D ). I have a lib file " libBox2D.so.2.1.0". I placed it in a separate folder libin my project folder (also the working directory for the executable).
I added -lBox2Dlinker to the command line arguments. (This means that I added "Box2D" as a library in the Eclipse GUI).

But when I try to start it, my application automatically prints that it cannot find the library file " libBox2D.so.2.1.0" with the following message:

error while loading shared libraries: libBox2D.so.2.1.0: cannot open shared object object: No such file or directory

I think he is looking for this library in /usr/lib/....

So: how can I tell the compiler / linker / "no matter what you need to know?" That my application should look for the library in the relative path " lib/libBox2D.so.2.1.0" (relative to the working dir)?

Maybe: can there be a problem on the Box2D download page (link here above), they say that this is the version 2.1.2, and this library is the version 2.1.0(if I look at the username)?

PS: I also tried putting it at the root of my project folder, but that failed ...

Any help would be greatly appreciated.
Thanks

+3
source share
2 answers

, LD_LIBRARY_PATH . LD_LIBRARY_PATH. , .

, , , , runtime , . .

  • . , .
  • , (, , ldconfig, , LD_LIBRARY_PATH ..).
  • , , - .

- . , GNU toolchain Linux, ld -rpath. - LD_LIBRARY_PATH ld -rpath '$ORIGIN/../lib' , , RPATH,... , .

+3

LD_LIBRARY_PATH.

, , "" . LD_LIBRARY_PATH .

, , "", . .

  • .
  • , , .
  • , .
  • .
  • , , .
  • , LD_LIBRARY_PATH.

:

export LD_LIBRARY_PATH=/path/to/dir
./path/to/executable
+2

Source: https://habr.com/ru/post/1754011/


All Articles