[英]Basic makefile/linking/library issue: No such file or directory
So my assignment essentially asks to make a Makefile to compile the sorted-list.c implementation into a library called libsl.a, and an executable called sl that runs the code in main.c. 因此,我的任务本质上是要求制作一个Makefile来将sorted-list.c实现编译成一个名为libsl.a的库,以及一个名为sl的可执行文件来运行main.c中的代码。
So I have written thus far: 到目前为止,我已经写了:
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
In the directory containing all my files, along with a file makefile , I type into the terminal: 在包含我所有文件以及文件makefile的目录中,我输入终端:
make
Now this is my first time doing all this, so I'm left to assume it has executed as I intended it to. 现在,这是我第一次执行所有这些操作,因此我假设它已按预期执行。 If not, please let me know.
如果没有,请告诉我。 That being said, I get the following error:
话虽如此,我得到以下错误:
-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 has the following question: Stackoverflow有以下问题:
Makefile is giving me an error - No such file or directory Makefile给我一个错误-没有这样的文件或目录
This seems to be the closest question/solution, but my executable sl appears to be placed properly (directly after the flags), as the answer indicates. 这似乎是最接近的问题/解决方案,但是正如答案所示,我的可执行文件sl似乎正确放置(直接在标志之后)。 I'm not sure if this matters, but I don't have any filed/directory called sl -- from my understanding, this will be the name of the executable that has yet to be created.
我不确定这是否重要,但是我没有任何名为sl的文件/目录-根据我的理解,这将是尚未创建的可执行文件的名称。
You have to place the name of the executable immediately after the -o
option as it is a parameter to this option. 您必须将可执行文件的名称放在
-o
选项之后,因为它是该选项的参数。 So 所以
cc -g -o sl main.o sorted-list.o
instead of 代替
cc -o -g sl main.o sorted-list.o
The manpage for cc(1)
should read something like this: cc(1)
的联机帮助页应显示以下内容:
-o output Name the output of the compilation output instead ofa.out.
This indicates that the name of your executable is an argument to the -o
option and thus has to appear immediately after the -o
option. 这表明可执行文件的名称是
-o
选项的参数,因此必须在-o
选项之后立即显示。
Please read the manpage cc(1)
for more details. 有关更多详细信息,请阅读手册
cc(1)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.