在 Makefile 中找不到指向的库文件

发布于 2024-11-29 07:11:09 字数 852 浏览 1 评论 0原文

我正在尝试编译这个工具。下面是其 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Hello爱情风 2024-12-06 07:11:09

问题是使用波浪号来表示“主目录”。仅当波浪号是单词中第一个非引号字符时,shell 才会进行波浪号扩展。 Makefile 从不进行波形符扩展。因此,在

gcc -L~/include ...

shell 中执行波形符扩展,gcc 将在当前目录中查找名为“~/include”的目录。但在

gcc -L ~/include ...

shell 中确实执行波形符扩展,而 gcc 看到的

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

是,它按预期工作。正确的做法是永远不要对主目录使用波浪号扩展,而只需在 Makefile 中适当地使用 $HOME,例如

INCLUDE_DIR     = $HOME/include

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文