For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > October 2007 > LD_LIBRARY_PATH









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author LD_LIBRARY_PATH
onkar

2007-10-27, 7:11 pm

how do I get rid of exporting LD_LIBRARY_PATH (to get rid of " error
while loading shared libraries") while compiling it self in the
Makefile.

how to incorporate some kind of export statement in Makeifle ??

Onkar

Logan Shaw

2007-10-27, 7:11 pm

onkar wrote:
> how do I get rid of exporting LD_LIBRARY_PATH (to get rid of " error
> while loading shared libraries") while compiling it self in the
> Makefile.


In general, you can get rid of LD_LIBRARY_PATH by using -L instead.

You may also want to produce executables that don't need LD_LIBRARY_PATH
set when it is time to run the executable (after build). In order to do
that, try using the -R or -rpath options to pass the path where the library
will actually be installed. Some compilers may require you to put a "-Wl,"
in front of "-rpath" in order to pass the flag through to the linker, so
you may need to use "-Wl,-rpath" instead of just "-rpath" in some cases.

> how to incorporate some kind of export statement in Makeifle ??


If by "export statement", you mean that you wish to set an environment
variable in the Makefile, you can do that, but it's not usually a good
way to solve the problem.

- Logan
meenakshi

2007-10-29, 4:23 am

On Oct 27, 6:21 pm, onkar <onkar....@gmail.com> wrote:
> how do I get rid of exporting LD_LIBRARY_PATH (to get rid of " error
> while loading shared libraries") while compiling it self in the
> Makefile.
>
> how to incorporate some kind of export statement in Makeifle ??
>
> Onkar


You can add the path to the directory containing libraries by defining
the variable LIBS in the Makefile as shown below:

LIBS=-L/path/to/libdir -lmylib -lm -lpthread

where mylib is the name of your library file

and then use this variable while compliling your program
test:test.o
$(CC) -o test test.o $(LIBS)

or alternatively, to use export statement add the following entry in
your Makefile

LD_LIBRARY_PATH=-L/path/to/libdir

export LD_LIBRARY_PATH

Meenakshi.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com