Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ld can't find library given -L

Tags:

makefile

ld

I have an object file main.o, and need to link it against a shared library at ./libsvm/libsvm.so.2. I have the following Makefile but it doesn't work for me. Library path has been specified in -L./libsvm but gcc -lsvm still can't find the shared library (libsvm.so.2).

This is my Makefile:

CC      = g++ -g
CFLAGS  = -Wall
HEADERS = -I./libsvm
OBJ     = main.o
LIBS    = -L./libsvm

all: lib $(OBJ)
     $(CC) $(LIBS) -lsvm $(OBJ) -o main

%.o: %.c
     $(CC) $(CFLAGS) $(HEADERS) -c -o $@ $<

lib:
     cd libsvm; make

It just works if link them directly, as in

ld main.o libsvm/libsvm.so.2 -o main

I wonder what's wrong in the Makefile. Error message is the following

g++ -g -L./libsvm -lsvm main.o -o main 
ld: library not found for -lsvm 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make: *** [all] Error 1
like image 332
qweruiop Avatar asked Nov 26 '25 17:11

qweruiop


1 Answers

-lsvm means use the file svm.so

But your library file has name svm.so.2. (Version 2)

So either rename or make a symbolic link with

ln -s svm.so.2 svm.so

Now the makefile should work.

like image 147
Valentin H Avatar answered Nov 28 '25 17:11

Valentin H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!