简体   繁体   中英

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.

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:

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:
Makefile is giving me an error - No such file or directory

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

You have to place the name of the executable immediately after the -o option as it is a parameter to this option. 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:

-o output
    Name the output of the compilation output instead of .

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.

Please read the manpage cc(1) for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM