c - gcc 无效的命令行选项

标签 c gcc compiler-errors

在 gcc 中使用此 makefile 进行编译时,我收到错误

cannot specify -o with -c, -S or -E with multiple files"

现在我猜想这与尝试两次编译同一个文件有关,但我不知道如何。

assembler : main.o assembler.o utils.o
    gcc -g -ansi -Wall -pedantic -lm main.o assembler.o utils.o -o assembler
main.o : main.c assembler.h utils.h
    gcc -c -ansi -Wall -pedantic -lm main.c assembler.h utils.h -o main.o
assembler.o : assembler.c
    gcc -c -ansi -Wall -pedantic -lm assembler.c -o assembler.o
utils.o : utils.c structs.h
    gcc -c -ansi -Wall -pedantic -lm utils.c structs.h -o utils.o

文件包含如下:

structs.h is included in utils.c,
utils.c is included in utils.h,
utils.h is included in assembler.c,
assembler.c is included in assembler.h,
assembler.h is included in main.c.

(:不知道为什么,它让我在代码形成中这样做......

最佳答案

您可能需要这个 makefile(只需从 gcc 命令中删除 .h 文件):

assembler : main.o assembler.o utils.o
    gcc -g -ansi -Wall -pedantic -lm main.o assembler.o utils.o -o assembler

main.o : main.c assembler.h utils.h
    gcc -c -ansi -Wall -pedantic main.c -o main.o

assembler.o : assembler.c
    gcc -c -ansi -Wall -pedantic assembler.c -o assembler.o

utils.o : utils.c structs.h
    gcc -c -ansi -Wall -pedantic utils.c -o utils.o

关于c - gcc 无效的命令行选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36135009/

相关文章:

c - 如何在程序开始处声明

c - 使用 fprintf 的奇怪 SEGFAULTS

c - memset() 没有在 c 中设置内存

c++ - GCC:如何只生成行号调试信息?

c - gcc 如何计算结构所需的空间?

c++ - 尝试在 code::blocks 中使用食人魔的基本教程会产生对 '__unwind_resume' 和 '__gxx_personality_v0' 的 undefined reference

java - "Incompatible types: void cannot be converted to ..."是什么意思?

C函数调用奇怪错误

C 操作数比较中的括号

gcc - 如何使用 Intel 语法内联汇编在 GCC 中设置变量?