Jenia Be Nice Please
Jenia Be Nice Please

Reputation: 2693

linker can't find libraries

I can't link my program "set-manipulation" with the libraries it needs.

Here is the message:

gcc -L/home/jenia/learn-c-the-hard-way/lib -lset_theory -g -Wall -I/home/jenia/learn-c-the-hard-way/lib/include -o "set-manipulation" main.o
/usr/bin/ld: cannot find -lset_theory
collect2: error: ld returned 1 exit status
Makefile:9: recipe for target 'set-manipulation' failed
make: *** [set-manipulation] Error 1

Here is the content of -L/home/jenia/learn-c-the-hard-way/lib:

  /home/jenia/learn-c-the-hard-way/lib:
  total used in directory 29 available 216513716
  drwxr-xr-x  3 jenia jenia 4096 Nov  1 12:47 .
  drwxr-xr-x  8 jenia jenia 4096 Oct 31 11:44 ..
  drwxr-xr-x  2 jenia jenia 4096 Nov  1 12:47 include
  -rwxr-xr-x  1 jenia jenia 6804 Nov  1 12:47 set_theory.a -- 50
  -rwxr-xr-x  1 jenia jenia 9664 Nov  1 12:47 set_theory.so -- 11

Here is the makefile which give the error (the makefile of set-manipulation program):

PREFIX?=/home/jenia/learn-c-the-hard-way
CFLAGS=-g -Wall -I${PREFIX}/lib/include
LDFLAGS=-L${PREFIX}/lib
INSTALL_DIR=${PREFIX}/apps

all: set-manipulation

set-manipulation: main.o
    gcc $(LDFLAGS) -lset_theory $(CFLAGS) -o "$@" main.o


install: all
    install -d $(INSTALL_DIR)/set-manipulation
    install set-manipulation $(INSTALL_DIR)/set-manipulation

clean:
    rm -f *.o
    rm -f set-manipulation
    rm -rf *.dSYM

Can someone please tell me how to link my program with it's library?

Upvotes: 0

Views: 10134

Answers (3)

Nikita Kakuev
Nikita Kakuev

Reputation: 1136

The -l argument expects the filename of specified library to be in a specific format. Namely, -lset_theory tells the linker to look for a file named libset_theory.a (or libset_theory.so).

Notice that your libraries don't have this prefix, so you either have to rename them, or use the semicolon and specify a filename:

gcc -L/home/jenia/learn-c-the-hard-way/lib -l:set_theory.a ...

Upvotes: 4

Ramy
Ramy

Reputation: 174

-L../../PATCH_to_library.a/set_theory.a

The library must be named libname.a/.so

Example : g++ Set.cpp -L../../libset_theory.a -lset_theory

If you don't have named library libname.a this dont't link the lib.

libtest.a

An corect link syntax :

g++ (LINK) -ltest

You see ? -l test don't include lib. l - lib

g++ -g -Wall -L/lib_dir/xx Foo.o Test.o -lset_theory -o test

Name of lib must be libset_theory.a

Upvotes: 4

Jonathan
Jonathan

Reputation: 129

I might be wrong here, but you don't seem to be including the libraries. I mean, you are icluding the paths, but not the libraries you whish to use.

Upvotes: 1

Related Questions