我收到链接器的错误,例如:
osd.o(.ndata+0x514):C:\Documents and Settings\Thomas\My Documents\PIC\dsPIC33FJ128GP802\On Screen Display\osd.c: multiple definition of `video_buff_vis_num'
main.o(.ndata+0x0):C:\Documents and Settings\Thomas\My Documents\PIC\dsPIC33FJ128GP802\On Screen Display\main.c: first defined here
osd.o(.ndata+0x515):C:\Documents and Settings\Thomas\My Documents\PIC\dsPIC33FJ128GP802\On Screen Display\osd.c: multiple definition of `video_buff_draw_num'
main.o(.ndata+0x1):C:\Documents and Settings\Thomas\My Documents\PIC\dsPIC33FJ128GP802\On Screen Display\main.c: first defined here
osd.o(.ndata+0x516):C:\Documents and Settings\Thomas\My Documents\PIC\dsPIC33FJ128GP802\On Screen Display\osd.c: multiple definition of `vid_format'
main.o(.ndata+0x2):C:\Documents and Settings\Thomas\My Documents\PIC\dsPIC33FJ128GP802\On Screen Display\main.c: first defined here
osd.o(.ndata+0x518):C:\Documents and Settings\Thomas\My Documents\PIC\dsPIC33FJ128GP802\On Screen Display\osd.c: multiple definition of `vid_line'
main.o(.ndata+0x4):C:\Documents and Settings\Thomas\My Documents\PIC\dsPIC33FJ128GP802\On Screen Display\main.c: first defined here
Run Code Online (Sandbox Code Playgroud)
这让我感到烦恼,因为在源代码中,我已经包含了这些定义可能来自唯一地方的警卫.
#ifndef OSD_H
#define OSD_H
// code here, including definitions for the above
#endif // OSD_H
Run Code Online (Sandbox Code Playgroud)
这让我很紧张.我已经清理,重建,并再次尝试.我甚至从头开始使用相同的文件创建一个新项目,我遇到了完全相同的问题!有人请赐教我为什么这不起作用!:)
与PIC-GCC V3.23编译(版本GCC用于PIC24F/H和dsPIC30F/33F微控制器).
如果有人想查看更多文件的来源,请告诉我.我不想过度拥挤这个页面.
如果您在多个.c文件中包含此标头,则您将拥有多个定义.你有main.c和osd.c.
这.h是函数和extern数据声明的正确位置.但是对于变量,您必须选择一个源文件.该#defined警卫不改变这种状况.
还有一点解释/分析:
1)每个.c源文件都是独立编译的.警卫只能防止在1次编译期间两次读取头文件.
2)您得到的错误是链接器(而不是编译器)错误.
当标头定义变量时,编译器会将其视为每个单独运行中的定义.链接器将检测多个实例.
| 归档时间: |
|
| 查看次数: |
391 次 |
| 最近记录: |