Cannot find library files directed to Makefile

I am trying to compile this tool. The following is the beginning of his Makefile:

CC = gcc CFLAGS = -Wall -O2 -D TRACES DFLAGS = -g -Wall -o0 CPPFLAGS= $(INCLUDES:%=-I %) LDFLAGS = $(LIBRARIES:%=-L %) LDLIBS = $(USED_TOOLS:%=-l%) MY_FILES = INCLUDE_DIR = ~/include TOOLBOX_INC = $(INCLUDE_DIR)/tools TOOLBOX_LIB = $(TOOLBOX_INC) USED_TOOLS = std_io stringutils INCLUDES = $(TOOLBOX_INC) LIBRARIES = $(TOOLBOX_LIB) 

I also have ~ / include / tools, which after compilation include std_io.o, libstd_io.a, stringutils.o and libstringutils.a

I get the following error:

 gcc -L ~/include/tools rank.o counterexample.o -lstd_io -lstringutils -o rank ld: library not found for -lstd_io collect2: ld returned 1 exit status make: *** [rank] Error 1 

I am not sure that things are not included correctly and why they do not find library files.

Edit:. I accidentally left a space between the -L and -I options. In addition, the paths should have been widened, I think. Now it works, thanks!

+8
c makefile gnu-make
source share
1 answer

The problem is that tilde means "Home Directory". A shell will do tilde expansion only if the tilde is the first character without quotation marks in the word. Makefiles never extends a tilde. So in

 gcc -L~/include ... 

the shell does not execute the tilde extension, and gcc will look for a directory with the name "~ / include" in the current directory. But in

 gcc -L ~/include ... 

the shell performs tilde expansion and gcc sees

 gcc -L /usr/username/include ... 

which works as expected. The right thing is to never use the tilde extension for the home directory, but just use $ HOME accordingly in the Makefile, for example.

 INCLUDE_DIR = $$HOME/include 
+12
source share

All Articles