Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

closed as off-topic by durron597, MichaelT, Snowman, Bart van Ingen Schenau, GlenH7 Oct 3 '15 at 23:48

  • This question does not appear to be about software development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the 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
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 1 '15 at 14:38

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/
  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

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