Not finding the library files directed to in Makefile
I am trying to compile this tool. Below is the beginning of its 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 compiling includes std_io.o, libstd_io.a, stringutils.o and libstringutils.a
I am getting 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 if things are not included correctly, and why it is not finding the library files.
Edit: turns out I accidentally left a space between the -L and -I options. Also, the paths had to be expanded I guess. It's working now, thanks!
The problem is the use of the tilde to mean "Home directory". A shell will do tilde expansion only if the tilde is the first nonquoted character in a word. Makefiles never do tilde expansion. Thus, in
gcc -L~/include ...
the shell does not perform tilde expansion and gcc will look for a directory named "~/include" in the current directory. But in
gcc -L ~/include ...
the shell does perform tilde expansion and gcc sees
gcc -L /usr/username/include ...
instead, which works as expected. The right thing to do is to never use tilde expansion for the home directory, but simply use $HOME appropriately in the Makefile, e.g.
INCLUDE_DIR = $$HOME/include
精彩评论