一个连接问题!

bh2001zhh 2006-08-11 12:40:36
/*****************************aa.h**********************/
#ifndef AA_H
#define AA_H

#define PI 3.14159

#ifdef _cplusplus
extern "c"
{
#endif

short sum(short x, short y);

#ifdef _cplusplus
};
#endif

#endif


/***************************aa.c*************/

#include "aa.h"
#include "test.h"
short sum(short x, short y)
{
short z;
z = x + y;
return z;
}


/***************test.h**************/
#include <dos.h>
#include <math.h>

#ifndef TEST_H
#define TEST_H


#ifdef _cplusplus
extern "C"
{
#endif

#ifdef _cplusplus
};
#endif

#endif


/************************test.c***********/
#include "test.h"
#include "aa.h"

void main(void)
{
short a, b, c;

a = 100;
b = 456;

c = sum(a, b);
printf("%d\n",c);

}


产生连接错误:undefined symbol:sum....
这是为什么?
thx!

...全文
149 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bh2001zhh 2006-08-11
  • 打赏
  • 举报
回复
有点麻烦,我还是把程序放在一起算了
Dong 2006-08-11
  • 打赏
  • 举报
回复
有啊,但你编译的时候好象没有办法编译到aa.o啊。程序是没有问题的,问题早早编译。

或者你的aa.h和aa.c不在同一目录下
bh2001zhh 2006-08-11
  • 打赏
  • 举报
回复
to:windking21(想玩玩WOW 真的那么难吗)
头文件路径应该没问题,编译都通过了!
bh2001zhh 2006-08-11
  • 打赏
  • 举报
回复
to:UPCC(杂食动物)
这样是不是就相当于一个文件了,有没有方法只包含头文件呢?
PMsg 2006-08-11
  • 打赏
  • 举报
回复
头文件路径设置问题吧
Dong 2006-08-11
  • 打赏
  • 举报
回复
#include "test.h"可以不包含
Dong 2006-08-11
  • 打赏
  • 举报
回复
#include "aa.h"
------------------
改为
#include "aa.c"
在编译的时候没有连接到aa.o,但你把包含改成aa.c的话就在test.o里面保护了sum的定义了

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧