2

I am trying to compile and install every custom module under it's own designated folder. (ex: /myApps/myLinux/compiled_app)

I had luck with Python so far, where my Python is compiled from source and lives in: /myApps/myLinux/python2.5 and "python2.5" -> /myApps/myLinux/python2.5.6-gcc463

So I can access this Python through a wrapper script that sets the right environment.

The question is recently I had to compile and add something called gperf3.0.4. So now it lives: /myApps/myLinux/gperf3.0 and "gperf3.0" -> /myApps/myLinux/gperf3.0.4-gcc463

The question is: How will I point to this lib if some other app needs to access it? Is it done through the LD_LIBRARY_PATH variable?

Dynamic
  • 5,786
mbilyanov
  • 129

2 Answers2

3

As you know, the -L flag to the linker is used to specify a path to search for libraries (static or shared) at link time.

The -R flag to the linker can be used to embed in the executable a path to be used to search at run time. This is needed if your shared library will be installed in a location not in the standard system shared library path.

To specify a custom flag to be used at link time to gcc, you can use the -Wl, prefix. So if you link your app with:

gcc -L/path/to/lib -Wl,-R/path/to/lib -o myapp myapp.o -lgperf

(Or similar) your app will link against the version of your library at that path and search that path for libraries at run time.

jimwise
  • 7,668
0

With gcc you can link to a lib in an arbitrary location by passing the full path to the linker just like any other object

$ gcc -c somefile.c
$ gcc -c mainfile.c
$ gcc somefile.o mainfile.o /path/to/libsomelib.so
  or
  gcc somefile.o mainfile.o -L/path/to/ -lsomelib
$ LD_LIBRARY_PATH=/path/to/ ./a.out