执行 makefile 时出现 Clang 错误
所以我有两个 C
文件,分别是 master.c
、slave.c
和 config.h
,我正在尝试构建一个 makefile 来执行这些文件,但出现错误。
我在 MacOS 上使用普通终端,在执行 make
时出现以下错误:
ss@US3FHIM0XQ86TJG: ~/project-2[master*]$ make
gcc -o master config.h master.c -g -I -std=gnu99
clang: error: cannot specify -o when generating multiple output files
make: *** [master] Error 1
这是我的 makefile 的样子:
CC = gcc
CFLAGS = -g -I -std=gnu99
all: master slave
master: config.h master.c
$(CC) -o $@ $^ $(CFLAGS)
slave: config.h slave.c
$(CC) -o $@ $^ $(CFLAGS)
clean:
rm master slave cstest logfile.*
有人能找出可能导致此问题的原因吗?
So I have two C
files which are master.c
, slave.c
and then config.h
and I'm trying to build a makefile for the execution of these files and I'm getting an error.
I'm using a normal terminal on MacOS and when executing make
I get the following error:
ss@US3FHIM0XQ86TJG: ~/project-2[master*]$ make
gcc -o master config.h master.c -g -I -std=gnu99
clang: error: cannot specify -o when generating multiple output files
make: *** [master] Error 1
Here is what my makefile looks like:
CC = gcc
CFLAGS = -g -I -std=gnu99
all: master slave
master: config.h master.c
$(CC) -o $@ $^ $(CFLAGS)
slave: config.h slave.c
$(CC) -o $@ $^ $(CFLAGS)
clean:
rm master slave cstest logfile.*
Can someone spot what might be causing this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除config.h。可以在命令行编译,省略“config.h”,即:
gcc -o master master.c -g -I -std=gnu99
有些人喜欢把 -o 放在最后:
gcc -g -I -std=gnu99 -c master.c -o master
更合适的方法是:
gcc -g -I/usr/include -std=gnu99 -c master.c -o master
一般来说,-I 有一个路径,例如如 -I/usr/include,但您可以省略 -I,因为您的编译器通常首先查找那里。
另外,如果在键入 make 时发生这种情况,您可能需要调整 Makefile 并省略 config.h。
一些小错误可以通过手动编译对象来修复(即,如上所述,gcc -g -I/usr/include -std=gnu99 -c master.c -o master)
编辑Makefile并删除config.h后,也许使用 -I/usr/include 或头文件的路径,您可以运行:
make clean
make all
或只是:
make Slave
或:
make master
等
Remove config.h. You can compile it on the command line and omit "config.h", ie:
gcc -o master master.c -g -I -std=gnu99
Some people like to put that -o at the end:
gcc -g -I -std=gnu99 -c master.c -o master
A more appropriate way would be:
gcc -g -I/usr/include -std=gnu99 -c master.c -o master
Generally, the -I has a path, such as -I/usr/include, but you can omit the -I as your compiler usually looks there first.
Also, you may have to tweak your Makefile and omit the config.h if it is happening when you type make.
Some little errors you can fix by compiling the object by hand (ie, as above, gcc -g -I/usr/include -std=gnu99 -c master.c -o master)
Once you edit Makefile and remove config.h, and perhaps use -I/usr/include or path to your headers, you can run:
make clean
make all
or just:
make slave
or:
make master
etc, etc
$^
是依赖项列表的占位符。这就是为什么规则运行命令
编译 .h 产生一个输出,编译 .c 产生另一输出。编译器不知道对其中哪一个应用 -o。正确的方法是使用规则
$<
是依赖项列表中第一项的占位符。这些规则正确运行 gcc$^
is a placeholder for the list of dependencies. That is why the ruleruns the command
Compiling .h produces one output, compiling .c produces another output. The compiler does not know to which of them to apply -o. The proper way is using rules
$<
is a placeholder for the first item in the list of dependencies. These rules run gcc properly