【发布时间】:2020-12-12 12:07:12
【问题描述】:
当我尝试构建文件时,它是在构建日志中以状态 1 终止的进程出现的。我目前正在学习 atmega328p,我将它用于这个项目(喇叭系统),我在这里有完整的代码hornsystem。谁能帮帮我,这是构建日志。
------------- Build: Debug in casestudy (compiler: GNU GCC Compiler for AVR)---------------
avr-gcc.exe -LC:\WinAVR\avr\lib -o bin\Debug\casestudy.elf obj\Debug\fuse.o obj\Debug\GPIO.o obj\Debug\Hornstate.o obj\Debug\main.o obj\Debug\modes.o
obj\Debug\temperature.o -mmcu=atmega328p -Wl,-Map=bin\Debug\casestudy.map,--cref
obj\Debug\Hornstate.o:(.data+0x0): multiple definition of `default_dutycycle'
obj\Debug\GPIO.o:(.data+0x0): first defined here
obj\Debug\main.o:(.data+0x0): multiple definition of `default_dutycycle'
obj\Debug\GPIO.o:(.data+0x0): first defined here
obj\Debug\modes.o:(.data+0x0): multiple definition of `default_dutycycle'
obj\Debug\GPIO.o:(.data+0x0): first defined here
obj\Debug\temperature.o:(.data+0x0): multiple definition of `default_dutycycle'
obj\Debug\GPIO.o:(.data+0x0): first defined here
Process terminated with status 1 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
【问题讨论】:
-
错误提示“
default_dutycycle的多个定义”并告诉您定义它的文件。在文件GPIO.h中,您有unsigned int default_dutycycle = 77;,并且此标头包含在其他几个文件中。最好不要在头文件中定义变量或函数:只定义它们的声明。 -
感谢您的信息,错误已解决。我想,既然我用过
ifndef,unsigned int default_dutycycle就不会每次都在main.c中定义了。 -
#ifndef作为“标头保护”是为了防止循环包含,而不是包含在多个编译单元中。 -
欢迎来到stackoverflow。如果您找到了问题的解决方案,那么如果您在答案中描述它然后接受该答案将非常有帮助 - 这将帮助其他有类似问题的用户更快地找到解决方案。如果我还可以建议编辑您的问题以使您更清楚您要做什么 - 例如,您要构建什么以及您要构建什么,这也可能有助于其他用户将您的问题识别为和他们一样。干杯。
-
不要链接到站外代码。在问题中包含相关代码。