【发布时间】:2010-12-01 10:14:11
【问题描述】:
我在 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++ 中设置什么来编译文件吗?
【问题讨论】:
-
请不要使用 Dev-C++:jasonbadams.net/20081218/why-you-shouldnt-use-dev-c
-
嗨,Karl,您使用什么进行 C/C++ 开发?我是新手,今天刚开始 C/C++。我的讲师不限制我们可以使用什么软件。有什么很酷的 IDE 推荐(最重要的是:“易于编译”)吗?
标签: c compilation header-files dev-c++