【问题标题】:Basic makefile/linking/library issue: No such file or directory基本的 makefile/linking/library 问题:没有这样的文件或目录
【发布时间】:2014-10-10 19:45:54
【问题描述】:

所以我的任务本质上是要求制作一个 Makefile 来将 sorted-list.c 实现编译成一个名为 libsl.a 的库,以及一个名为 sl 的可执行文件,它运行 main.c 中的代码。

到目前为止,我已经写了:

cc=gcc

sl : main.o sorted-list.o
    cc -o -g sl main.o sorted-list.o

main.o : main.c sorted-list.h
sorted-list.o : sorted-list.c sorted-list.h

ar : rcs libsl.a sorted-list.o

clean :
    rm sl main.o sorted-list.o

在包含我所有文件的目录中,连同一个文件makefile,我在终端中输入:

make

现在这是我第一次做这一切,所以我只能假设它已经按照我的预期执行了。如果没有,请告诉我。话虽如此,我收到以下错误:

-bash-4.1$ make
cc    -c -o sorted-list.o sorted-list.c
cc -o -g sl main.o sorted-list.o
cc: sl: No such file or directory
make: *** [sl] Error 1

Stackoverflow 有以下问题:
Makefile is giving me an error - No such file or directory

这似乎是最接近的问题/解决方案,但我的可执行文件 sl 似乎被正确放置(直接在标志之后),如答案所示。我不确定这是否重要,但我没有任何名为 sl 的文件/目录——据我了解,这将是尚未创建的可执行文件的名称。

【问题讨论】:

    标签: c makefile static-linking


    【解决方案1】:

    您必须将可执行文件的名称紧跟在-o 选项之后,因为它是该选项的参数。所以

    cc -g -o sl main.o sorted-list.o
    

    而不是

    cc -o -g sl main.o sorted-list.o
    

    cc(1) 的手册页应该是这样的:

    -o 输出 将编译的输出命名为 output 而不是 a.out

    这表明您的可执行文件的名称是-o 选项的参数,因此必须立即出现在-o 选项之后。

    请阅读手册页cc(1) 了解更多详情。

    【讨论】:

      猜你喜欢
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      • 2016-04-29
      • 2016-02-11
      • 2014-12-09
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      相关资源
      最近更新 更多