文件包含问题 [英] File included problems

查看:63
本文介绍了文件包含问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题,我有三个文件,例如:


/ ****啊******* /

#define X1 10

#define X2 10

......................


/ **** bc ******* /

#include" a.h"

int add (int x,int y)

{

返回x + y;

}


/ **** cc ******* /

#include" a.h"

void main()

{

int x,y;

x = y = 10;

add(x,y);

}


为什么编译器会给我错误:未定义引用''add'',我使用的
编译器是Dev-C ++。

谢谢,任何帮助将不胜感激。

wangshi

Hi, I got a problem, I have three files, for example:

/****a.h*******/
#define X1 10
#define X2 10
......................

/****b.c*******/
#include "a.h"
int add(int x,int y)
{
return x+y;
}

/****c.c*******/
#include "a.h"
void main()
{
int x,y;
x = y = 10;
add(x,y);
}

why the compiler give me the error: undefined reference to ''add'', the
compiler i used is Dev-C++.
thanks, any help will be appreciated.
wangshi

推荐答案

Stoneforever写道:
Stoneforever wrote:

我遇到了问题,我有三个文件,例如:


/ ****啊* ****** /

#define X1 10

#define X2 10
Hi, I got a problem, I have three files, for example:

/****a.h*******/
#define X1 10
#define X2 10



你需要一个原型加入:


extern int add(int x,int y);

You require a prototype for add in here:

extern int add(int x,int y);


......................


/ *** * bc ******* /

#include" a.h"

int add(int x,int y)

{

返回x + y;

}


/ **** cc ******* /

#include" a.h"

void main()
......................

/****b.c*******/
#include "a.h"
int add(int x,int y)
{
return x+y;
}

/****c.c*******/
#include "a.h"
void main()



int main(void)

int main(void)


{

int x,y;

x = y = 10;

add(x,y);

}


为什么编译器会给我错误:未定义引用''add'',
我使用的
编译器是Dev-C ++。

谢谢,任何帮助都将不胜感激。

wangshi
{
int x,y;
x = y = 10;
add(x,y);
}

why the compiler give me the error: undefined reference to ''add'', the
compiler i used is Dev-C++.
thanks, any help will be appreciated.
wangshi



-

Ian Collins。


--
Ian Collins.


Ian Collins写道:
Ian Collins wrote:

Stoneforever写道e:
Stoneforever wrote:



<在另一个源文件中定义的snip函数>

<snip function defined in one source file used in another>


>为什么编译器会给我错误:未定义引用''add'',我使用的编译器是Dev-C ++。
谢谢,任何帮助将不胜感激。
>why the compiler give me the error: undefined reference to ''add'', the
compiler i used is Dev-C++.
thanks, any help will be appreciated.



除了Ian所说的你需要了解如何让Dec-C ++转换成
编译并链接在一起两个C文件。如何做到这一点是实现

依赖,所以你需要阅读Dev-C ++的文档,如果你需要进一步的帮助,请在群组或邮件列表上查询Dec -C ++。我们

没有处理如何在阳光下驾驶每一套工具。

-

Flash Gordon


Stoneforever写道:
Stoneforever wrote:

我遇到了问题,我有三个文件,例如:


/ ****啊******* /

#define X1 10

#define X2 10

.....................


/ **** bc ******* /

#include" a.h"

int add(int x,int y)

{

返回x + y;

}


/ **** cc ******* /

#包括a.h

void main()

{

int x,y;

x = y = 10;

add(x,y);

}


为什么编译器会给我错误:undefined reference为了添加,我使用的

编译器是Dev-C ++。

谢谢,任何帮助将不胜感激。
Hi, I got a problem, I have three files, for example:

/****a.h*******/
#define X1 10
#define X2 10
.....................

/****b.c*******/
#include "a.h"
int add(int x,int y)
{
return x+y;
}

/****c.c*******/
#include "a.h"
void main()
{
int x,y;
x = y = 10;
add(x,y);
}

why the compiler give me the error: undefined reference to ''add'', the
compiler i used is Dev-C++.
thanks, any help will be appreciated.



这取决于你如何编译。我不知道任何关于Dev-C ++的知识,但是这里有3次尝试

用gcc编译,第一次失败,第二次工作但是

通常不是理想的方法,

第三是......不太正确。 (我希望添加

函数编译成单独的.a或.so而不是

只是构建一个目标文件,但是对于某些内容

这很简单,这太过分了。)


It depends on how you are trying to compile. I don''t
know anything about Dev-C++, but here are 3 attempts
to compile with gcc, the first fails, the second works but
is not generally the desirable approach, and the
third is...less incorrect. (I would prefer that the add
function be compiled into a seperate .a or .so rather
that just building an object file, but for something
this simple, that''s overkill.)


这篇关于文件包含问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆