9

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?

Jens
  • 5,767
  • 5
  • 54
  • 69
karthik
  • 345
  • 3
  • 5
  • 11

2 Answers2

12

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.

Tamás
  • 47,239
  • 12
  • 105
  • 124
  • 1
    your amazing tamas your just amazing.my project manager has assigned me these work and i'm very new to these makefiles just 9 days so i'm working on buti'm unable to figure out the error and the solution you gave its working too much right thank you once again tamas – karthik Jun 23 '11 at 08:54
  • tamas can you tell me the way to create a library a static library in makefiles i want a library named as gola.a and the .o files are gohh.o hola.o something like that i want that to be created but using the makefile how to write that code to create library file could you please tell me in the form of makefile – karthik Jun 23 '11 at 08:56
  • Please ask it in a different question on Stack Overflow and someone (maybe me) will answer there. It is best to keep one thread dedicated to one particular question. – Tamás Jun 23 '11 at 09:02
  • What happens if the library is in a completely different path? Can I write something like -L~/foo1/foo2/ Thanks – desmond13 Nov 23 '16 at 11:03
  • I found a good answer here. They explain also the difference, in a makefile, between -l and -L http://stackoverflow.com/questions/519342/what-is-the-difference-between-i-and-l-in-makefile – desmond13 Nov 23 '16 at 11:16
0

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

slfan
  • 8,950
  • 115
  • 65
  • 78