我在 windows vista 上使用 Dev-C++。我有 3 个文件位于同一目录中。他们是:
- math_functions.h
- math_functions.c
- test3.c
math_functions.h 代码:
int sum (int x, int y);
float average (float x, float y, float z);
math_functions.c 代码:
int sum (int x, int y)
{
return (x + y);
}
float average (float x, float y, float z)
{
return (x + y + z) / 3;
}
test3.c 代码:
#include <stdio.h>
#include "math_functions.h"
main ()
{
int theSum = sum (8, 12);
float theAverage = average (16.9, 7.86, 3.4);
printf ("the sum is: %i ", theSum);
printf ("and the average is: %f \n", theAverage);
printf ("average casted to an int is: %i \n", (int)theAverage);
}
它无法编译。我得到的错误信息是:
C:\Users\eSum\AppData\Local\Temp\ccKmdaaa.o(.text+0x3a) In function `main':
[Linker error] undefined reference to `sum'
[Linker error] undefined reference to `average'
C:\Users\eSum\AppData\Local\Temp\ccKmdaaa.o(.text+0x3a) ld returned 1 exit status
我使用在 ubuntu 中编译的完全相同的代码(我使用虚拟机运行 ubuntu,即 vmplayer),它编译时没有错误。
我需要在 Dev-C++ 中设置什么来编译文件吗?