找不到Makefile中定向到库文件

找不到Makefile中定向到库文件

本文介绍了找不到Makefile中定向到库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译这个工具。下面是它的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)

我也有〜/有/工具,编译后包括std_io.o,libstd_io.a,stringutils.o和libstringutils.a

I also have ~/include/tools which after compiling includes std_io.o, libstd_io.a, stringutils.o and 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

我不知道,如果事情不正确包括,为什么它没有找到库文件。

I am not sure if things are not included correctly, and why it is not finding the library files.

编辑:原来我不小心留下-L和-I选项之间的空间。此外,路径必须扩大我猜。它的工作现在,谢谢!

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!

推荐答案

的问题是使用波浪号的意思是主目录。一个shell会做只有当波浪线是一个字的第一个带引号的字波浪线扩展。 Makefile文件永远不会做波浪线扩展。因此,在

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 ...

壳的执行波浪线扩展和GCC会寻找一个名为〜/包括在当前目录。但在

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 ...

确实执行波浪线扩展和gcc看到

the shell does perform tilde expansion and gcc sees

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

相反,如预期其中工程。做正确的事是永远不要用波浪线扩展主目录,但只是在Makefile中恰当地使用$ HOME,例如

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

这篇关于找不到Makefile中定向到库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:40