在 Makefile 中找不到指向的库文件
我正在尝试编译这个工具。下面是其 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)
我还有 ~/include/tools,编译后包括 std_io.o、libstd_io.a、stringutils.o 和 libstringutils.a
我收到以下错误:
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
我不确定事情是否不正确正确包含,以及为什么找不到库文件。
编辑:结果是我不小心在 -L 和 -I 选项之间留下了空格。另外,我想路径也必须扩展。现在可以使用了,谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是使用波浪号来表示“主目录”。仅当波浪号是单词中第一个非引号字符时,shell 才会进行波浪号扩展。 Makefile 从不进行波形符扩展。因此,在
shell 中不执行波形符扩展,gcc 将在当前目录中查找名为“~/include”的目录。但在
shell 中确实执行波形符扩展,而 gcc 看到的
是,它按预期工作。正确的做法是永远不要对主目录使用波浪号扩展,而只需在 Makefile 中适当地使用 $HOME,例如
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
the shell does not perform tilde expansion and gcc will look for a directory named "~/include" in the current directory. But in
the shell does perform tilde expansion and gcc sees
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.