hasan bucak
hasan bucak

Reputation: 75

how to add interdependent libraries in a makefile

I need to make a makefile for my project and I have two interdependent libraries which are libpcsc.so and libccid.so .

could someone tell me what my mistake is? Thanks for your answers in advance.

and please let me know when you need more information.

my makefile is like:

by the way, one of lib directory is /home/hasanbucak/Desktop/pcsc-lite-1.8.23/src/.libs/ and other one's is usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Linux/

 CC = gcc

 LIB_DIRS = -L/home/hasanbucak/Desktop/pcsc-lite-1.8.23/src/.libs/ 
 -L../../usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Linux/ 

 INCLUDE_DIR = /home/hasanbucak/Desktop/ccid-1.4.28/src/ #ccid_usb.h

 CFLAGS = -g -Wall

obj-y:= smcard

default: all


all: smcard

smcard: 
    $(CC) $(CFLAGS) $(LIB_DIRS)  -I$(INCLUDE_DIR) -c -o $(obj-y).o $(obj-y).c
    $(CC) $(CFLAGS) -lccid -lpcsclite  $(LIB_DIRS) -I$(INCLUDE_DIR) -o $(obj-y) $(obj-y).c  




clean:
    rm $(obj-y).o $(obj-y)

and when I write make in terminal , it says:

hasanbucak@ubuntu:~/Desktop/hasan$ make
gcc -g -Wall -L/home/hasanbucak/Desktop/pcsc-lite-1.8.23/src/.libs/ -L../../usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Linux/   -I/home/hasanbucak/Desktop/ccid-1.4.28/src/ -c -o smcard.o smcard.c
gcc -g -Wall -lccid -lpcsclite  -L/home/hasanbucak/Desktop/pcsc-lite-1.8.23/src/.libs/ -L../../usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Linux/  -I/home/hasanbucak/Desktop/ccid-1.4.28/src/ -o smcard smcard.c  
/usr/bin/ld: cannot find -lccid
collect2: error: ld returned 1 exit status
Makefile:20: recipe for target 'smcard' failed
make: *** [smcard] Error 1

Upvotes: 0

Views: 225

Answers (1)

Robindar
Robindar

Reputation: 484

Make already told you what was wrong with the Makefile:

/usr/bin/ld: cannot find -lccid

You should specify the path to ccid properly:

LIB_DIRS = -L/home/hasanbucak/Desktop/pcsc-lite-1.8.23/src/.libs/ 
  -L/usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Linux/

Note that /usr and ../../usr are not at all the same directory.

The first one is absolute (i.e. relative to your root directory), while the second is relative, it expands to ~/Desktop/hasan/../../usr, which is equivalent to /home/hasanbucak/usr.

Upvotes: 2

Related Questions