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,746
  • 9
  • 45
  • 73
mbilyanov
  • 129
  • 1
  • 4
  • I think: At compile time, it is some kind of env.variable with a path to the lib and then at run-time the LD_LIBRARY_PATH variable? – mbilyanov Jul 05 '12 at 00:11
  • 4
    I'm voting to close this question as off-topic because this is an implementation question, but it is too old to migrate. – durron597 Oct 01 '15 at 14:38

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,433
  • 1
  • 30
  • 32
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
user2906
  • 31
  • 5
  • If you set the runtime link path of the executable, you can create an executable which does *not* need LD_LIBRARY_PATH, even though it uses a shared library in a non-standard location. – jimwise Jan 26 '13 at 20:03
  • I actually had the impression that using full path has the side-effect of actually setting rpath, but I am not sure about it. – Jan Hudec Jan 28 '13 at 10:11