Using library paths in makefiles

2020-07-09 02:07发布

问题:

I have written a makefile like this:

HEADER = -I./cygdrive/c/cpros/kajj/source4
LIBB = -L./cygdrive/c/cpros/kajj/source1   -L./cygdrive/c/cpros/kajj/source2
LIBRA = -larith -ldekk

target : game.o 
    gcc $(HEADER)   $(LIBB)  $<  -o  $@  $(LIBRA)   

game.o : game.c 
    gcc -c  game.c

I have created my own static library and included the header file path and library path. When I execute my makefile it gives an error saying that /usr/lib/gcc cannot find -larith -ldekk.

It is pointing to the lib/ directory but it is not over there: -ldekk and -larith are in source1 and source2 files respectively.

How to solve this error?

回答1:

Instead of -L./cygdrive/c, use -L/cygdrive/c. The dot makes the library path relative from the current directory, i.e. it will look for a cygdrive subfolder of the current folder instead of drive C.



回答2:

My revised Makefile libraries line is:

LIBS=-L/usr/lib/arm-linux-gnueabihf -lrtlsdr -lpthread -lm

This solved the issue in a Raspberry Pi 4 running the latest Raspbain as of Dec 30, 2019