【发布时间】:2017-12-10 22:45:03
【问题描述】:
目前正在尝试在 Debian 上使用 GCC,以及一个 makefile,因为我正在制作我的头文件之一。每当我尝试“制作”makefile 时,都会收到如下错误:
setup.o:在函数“设置”中:
setup.c:(.text+0x0): `setup'的多重定义
finalkek.o:finalkek.c:(.text+0x0): 首先定义在这里
collect2: ld 返回 1 个退出状态
make: *** [projExec] 错误 1
我的 makefile 如下所示:
projExec: finalkek.o setup.o
gcc -o projExec finalkek.o setup.o
finalkek.o: finalkek.c setup.h
gcc -c finalkek.c
setup.o: setup.c
gcc -c setup.c
finalkek.c 是我的主文件,setup 是我的头文件。
在我的主文件中,这是我唯一一次提到它:
include "setup.h" // Using the double quotes for a custom header...
void main()
{
setup();
rest of code here...
}
在我的头文件setup.h中,我有这样的:
void setup()
{
rest of code here...
}
【问题讨论】:
-
为什么在
setup.h中实现setup()函数?setup.c中有什么内容? (是不是有些错字?)。您的问题可能是多次导入错误。如果您进行适当的修改,我们可以提供明确的答案。 -
虽然和问题无关,但
void main()应该是int main(void)。如果你有一本书或教程告诉你使用void main(),找一个作者懂C的更好的。 -
另外,我从标题和标签中删除了“Debian”,因为它几乎肯定是不相关的。另外,请将所有代码(包括makefile)发布在帖子本身而不是截图
-
@KyrSt 可以,只需要从nano获取即可。
-
void setup() {应该在 setup.c,而不是 setup.h