我有以下代码布局
头文件.h
#ifndef _header_h
#define _header_h
void empty(float *array, int l)
{
int i;
for (i=1 ; i<=l ; i++)
{
array[i]=0;
}
}
#endif
和两个文件(我们称它们为 file1.c 和 file2.c)
#include "header.h"
void function/*1 or 2*/(){
....
empty(a,b);
....
}
所以编译工作正常,但链接器命令失败,因为编译器说有重复的函数定义。如何在仍然使用头文件的情况下避免这种情况?当我只在标头中定义函数并创建另一个包含完整函数的 .c 文件时,它工作正常。我一直认为在标题中声明它是要走的路。