Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

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?

share|improve this question
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? –  symbolix Jul 5 '12 at 0:11

2 Answers 2

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.

share|improve this answer

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
  gcc somefile.o mainfile.o -L/path/to/ -lsomelib
$ LD_LIBRARY_PATH=/path/to/ ./a.out
share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.