LD_LIBRARY_PATH - Unix

This is a discussion on LD_LIBRARY_PATH - Unix ; 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...

+ Reply to Thread
Results 1 to 3 of 3

Thread: LD_LIBRARY_PATH

  1. LD_LIBRARY_PATH

    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


  2. Re: LD_LIBRARY_PATH

    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

  3. Re: LD_LIBRARY_PATH

    On Oct 27, 6:21 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.
    >
    > 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.


+ Reply to Thread