How to link shared library in Makefile

20,661

isinf is part of math library. Try including -lm.

$(CC) -I$(INCPATH) -L$(LIBPATH) -o driver driver.c -lprivate -lm
Share:
20,661
mfu
Author by

mfu

Updated on September 13, 2020

Comments

  • mfu
    mfu over 3 years

    I am trying to make the following makefile on olaris SPARC

    CC=/usr/sfw/bin/gcc
    
    INCPATH=/export/home/compkvar/compile/inc
    LIBPATH=/export/home/compkvar/compile/lib
    SOURCEPATH=/export/home/compkvar/compile/src
    
    .c.o:
            $(CC) -c $< $(INCPATH) -I.
    
    
    PSOURCE = driver.c
    
    driver : driver.o 
                    $(CC) -I$(INCPATH) -L$(LIBPATH) -o driver driver.c -lprivate 
    
    all : driver
    
    clean :
        rm driver.o driver
    

    but i got error the following ;

    /usr/sfw/bin/gcc -I/export/home/compkvar/compile/inc -L/export/home/compkvar/compile/lib -o driver driver.c -lprivate 
    Undefined                       first referenced
     symbol                             in file
    isinf                               /export/home/compkvar/compile/lib/libprivate.so
    ld: fatal: Symbol referencing errors. No output written to driver
    collect2: ld returned 1 exit status
    *** Error code 1
    make: Fatal error: Command failed for target `driver'
    

    libprivate.so shared library is exist under '/export/home/compkvar/compile/lib' path but it couldn't found:

    bash-3.00$ pwd
    /export/home/compkvar/compile/lib
    bash-3.00$ ls -latr
    total 14116
    drwxr-xr-x   2 compkvar other        512 Sep 12 15:34 .
    drwxr-xr-x   5 compkvar other        512 Sep 12 15:34 ..
    -rwxrwxrwx   1 compkvar other     761180 Sep 12 15:43 libprivate.so
    -rwxrwxrwx   1 compkvar other    2275492 Sep 12 15:43 libPricingFunctions.so
    -rwxrwxrwx   1 compkvar other    1104576 Sep 12 15:43 libprfUtilities.a
    -rwxrwxrwx   1 compkvar other    2275492 Sep 12 15:43 libPricingFunctions.so.1
    -rwxrwxrwx   1 compkvar other     761180 Sep 12 15:43 libprivate.so.1
    bash-3.00$ 
    

    Thanks in advance.

  • mfu
    mfu over 10 years
    Thanks for your response. We have tried to compile it with -lm flag but it failed again to find "isinf". /usr/sfw/bin/gcc -I/export/home/compkvar/compile/inc -L/export/home/compkvar/compile/lib -o driver driver.c -lprivate -lm Undefined first referenced symbol in file isinf /export/home/compkvar/compile/lib/libprivate.so ld: fatal: Symbol referencing errors. No output written to driver collect2: ld returned 1 exit status *** Error code 1 make: Fatal error: Command failed for target `driver'