Search code examples
bashcompilationg++ld

Local install of GNU MP, how to access it from ld?


I have a compiled local install of GMP:

/path/to/gmp
    .../lib/gmp.h
    .../include/[gmp_binaries.etc]

Now, I export the path, just to test the install; I'll add symlinks in some central location once I get it working:

export LD_LIBRARY_PATH=/path/to/gmp:$LD_LIBRARY_PATH

g++ -lgmp

// error: /usr/bin/ld: cannot find -lgmp

export LD_LIBRARY_PATH=/path/to/gmp/include:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/path/to/gmp/lib:$LD_LIBRARY_PATH

g++ -lgmp

// error: /usr/bin/ld: cannot find -lgmp

Basically, my question is: how do I connect my local libraries to ld?

(And the point is installing content without sudo, so I can't "just ____," for the most part)


Solution

  • -l requires a -L location to search in g++. Make does not follow your LD_LIBRARY_PATH. Make needs a specific location to search for specific libraries not included in /usr/lib

    # define library paths in addition to /usr/lib
    # if I wanted to include libraries not in /usr/lib I'd specify
    # their path using -Lpath, something like:
    LFLAGS = -L/home/newhall/lib -L../lib

    From this site

    Find your libgmp file, and link as follows:

    g++ -L/path/to/libgmp/ -lgmp