有一个客户头文件包含一些简单的函数,并在两个不同的 .c 文件中使用这些函数
样本头文件.h
#ifndef SAMPLEHEADER_H
#define SAMPLEHEADER_H
# include <stdio.h>
add(int a, int b)
{
printf("Added value = %d\n", a + b);
}
multiply(int a, int b)
{
printf("Multiplied value = %d\n", a * b);
}
#endif
文件1.c
# include <stdio.h>
# include "sampleheader.h"
int file 2();
int main (){
add (a, b);
if some condition matches call -- file2 (a,b);
return 0;
}
文件2.c
# include <stdio.h>
int file2 (){
multiply (a, b);
return 0;
}
我正在运行以下命令来编译代码:
gcc -c -o file1.o file1.c
gcc -c -o file2.o file2.c
gcc -o target file1.o file2.o
低于警告
warning: implicit declaration of function ‘multiply’ [-Wimplicit-function-declaration]
请帮助我避免“[-Wimplicit-function-declaration]”警告。
也试过 include "sampleheader.h"
了file2.c
,然后它抛出一个错误" multiple definition of add;
/tmp/ccTOAq1U.o:file2.c:(.text+0x0): first defined here'"
抱歉,如果这是重复性问题。