main.c如何包含其它.c文件
目前有sd.h,mmc.c, main.c文件。其中 sd.h定义了sd.c的函数原型以及部分变量;
如何在main.c中包含 sd.h,mmc.c文件?main.c与其它 .c文件,.h文件应该如何管理。
我的方法是,
1. 在mmc.c中 #include "sd.h";包含函数原型定义
2.用一个 main.h文件,其中 #include "sd.h";
3. 在main.c中 #include "main.h".
结果编译时 报错, 对mmc.c中函数报 没有声明? 为什么。因为 sd.c已经包含了 sd.h,而sd.h已经对 sd.c的函数原型申明了。
报错如下,细看后 意思是说:重复定义了!!
G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:172: multiple definition of `SD_read_byte'
main.o:G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:172: first defined here
mmc.o: In function `SD_write_byte':
G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:205: multiple definition of `SD_write_byte'
main.o:G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:205: first defined here
mmc.o: In function `SD_write_command':
G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:144: multiple definition of `SD_write_command'
main.o:G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:144: first defined here
mmc.o: In function `SD_init':
G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:26: multiple definition of `SD_init'
main.o:G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:26: first defined here
mmc.o: In function `SD_write_sector':
G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:227: multiple definition of `SD_write_sector'
main.o:G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:227: first defined here
mmc.o: In function `SD_read_block':
G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:277: multiple definition of `SD_read_block'
main.o:G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:277: first defined here
mmc.o: In function `SD_read_sector':
G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:307: multiple definition of `SD_read_sector'
main.o:G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:307: first defined here
mmc.o: In function `SD_read_cid':
G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:328: multiple definition of `SD_read_cid'
main.o:G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:328: first defined here
mmc.o: In function `SD_read_csd':
G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:339: multiple definition of `SD_read_csd'
main.o:G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:339: first defined here
mmc.o: In function `SD_read_byte':
G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../mmc.c:172: multiple definition of `SPI_Mode'
main.o:G:\work\avr\avrl lesson\ceshi\SD\ver1.5 zj write\default/../uart_new.h:49: first defined here
make: *** [MMCSD.elf] Error 1
但是 sd.h中已经定义了
//Prototypesinline U08 SD_read_byte(void);inline void SD_write_byte(U08);extern void SD_read_block(U08 *,U08 *,U16);extern U08 SD_init(void);extern U08 SD_read_sector (U32,U08 *);extern U08 SD_write_sector (U32,U08 *);extern U08 SD_write_command (U08 *);extern U08 SD_read_csd (U08 *);extern U08 SD_read_cid (U08 *);