模块化编程中的问题 [英] problem in modular programing

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

问题描述

让我们看下面给出的代码

这里我试图做mudular编程

/ *这是我的主要编程。* /

/*mmod.c*/

#include< stdio.h>

#include" mod1.h"

int main( void)

{

int n;

puts(输入n的值);

scanf("%d"& n);

printf("%d的平方为: - %ld",n,sqr(n));

返回0;

}


/ *这是我的辅助模块* /

/*mod1.c* /

#include" mod1.h"


long sqr(int x)

{

返回((长)((x)*(x)));

}


/ *这是我的头文件* /

/*mod1.h*/

long sqr(int x);

当我编译main&二级模块,每件事都没问题,但是因为我想要链接它们,所以有一个链接器错误,即未定义的符号_sqr


在mmod.exe中

解决方案



ashu写道:

让看下面给出的代码
这里我试图做mudular编程

/ *这是我的主要编程。* /
/*mmod.c*/
#include< stdio.h>
#include" mod1.h"
int main(void)
{
int n;
puts(" enter the值n;;
scanf(%d,& n);
printf(%d的平方为: - %ld,n,sqr(n)) ;
返回0;
}

/ *这是我的辅助模块* /
/*mod1.c*/
#include" mod1 .h"

long sqr(int x)
{
返回((长)((x)*(x)));
}

/ *这是我的头文件* /
/*mod1.h*/
long sqr(int x);

当我编译mai n&二级模块,每件事都没问题,但是当我试图链接它们时,有一个链接器错误,即mmod.exe中的未定义符号_sqr




< OT>

您是否记得告诉链接器mod1.o [bj]?确切的方式

将取决于你的工具链。

< / OT>


-

BR,Vladimir


" ashu"写道:

让我们看下面给出的代码
这里我试图做mudular编程

/ *这是我的主要编程。* /
/*mmod.c*/
#include< stdio.h>
#include" mod1.h"
int main(void)
{
int n;
puts(输入n的值);
scanf("%d",& n);
printf("%of square) d是: - %ld",n,sqr(n));
返回0;
}

/ *这是我的辅助模块* /
/ * mod1.c * /
#include" mod1.h"

long sqr(int x)
{
返回((长)((x) *(x)));
}

/ *这是我的头文件* /
/*mod1.h*/
long sqr(int x) ;

当我编译main&二级模块,每件事都没问题,但是当我试图链接它们时,在mood.exe中有一个链接器错误,即未定义的符号_sqr



>


对我来说还行。这种问题与你的编译器设置有关,并且这个组没有讨论这样的事情。所以重新发布一个处理你的编译器的小组。但首先,搜索您选择的组,例如make

file,IDE,project。使用Google网上论坛的高级搜索功能。这不是你第一个遇到这个问题的人。




ashu写道:

让我们看下面给出的代码
这里我试图做mudular编程

/ *这是我的主要编程。* /
/*mmod.c * /
#include< stdio.h>
#include" mod1.h"
int main(void)
{
int n;
puts(输入n的值);
scanf("%d",& n);
printf("%d的平方为: - %ld",n ,sqr(n));
返回0;
}

/ *这是我的辅助模块* /
/*mod1.c*/
#include" mod1.h"

long sqr(int x)
{
return((long)((x)*(x))); /*mod1.h*/
long sqr(int x);

当我编译main&二级模块,每件事都没问题,但是当我试图链接它们时,有一个链接器错误,即mmod.exe中的未定义符号_sqr






我没有看到任何可能导致此问题的错误。

它可能是一个编译和链接的方式有问题。特别是,

检查.c文件的顺序。

如果您使用行命令或生成文件,请发布它。
< br $>
亲切问候。


PS:对所有读者:我知道编译器命令是OT,但它是

最佳方式放弃该错误是在源头。


lets look at the code given below
here i m trying to do mudular programming
/* this is my main prog.*/
/*mmod.c*/
#include<stdio.h>
#include "mod1.h"
int main(void)
{
int n;
puts("enter the value of n");
scanf("%d",&n);
printf("the square of %d is :- %ld",n,sqr(n));
return 0;
}

/*this is my secondary module */
/*mod1.c*/
#include "mod1.h"

long sqr(int x)
{
return ((long)((x)*(x)));
}

/*this is my header file*/
/*mod1.h*/
long sqr(int x);
when i compile main & secondary module,every thing is ok, but as i am

trying to link them,there is a linker error i.e,undefined symbol _sqr

in mmod.exe

解决方案


ashu wrote:

lets look at the code given below
here i m trying to do mudular programming
/* this is my main prog.*/
/*mmod.c*/
#include<stdio.h>
#include "mod1.h"
int main(void)
{
int n;
puts("enter the value of n");
scanf("%d",&n);
printf("the square of %d is :- %ld",n,sqr(n));
return 0;
}

/*this is my secondary module */
/*mod1.c*/
#include "mod1.h"

long sqr(int x)
{
return ((long)((x)*(x)));
}

/*this is my header file*/
/*mod1.h*/
long sqr(int x);
when i compile main & secondary module,every thing is ok, but as i am

trying to link them,there is a linker error i.e,undefined symbol _sqr

in mmod.exe



<OT>
Did you remember to tell your linker about mod1.o[bj]? The exact way
will depend on your toolchain.
</OT>

--
BR, Vladimir


"ashu" writes:

lets look at the code given below
here i m trying to do mudular programming
/* this is my main prog.*/
/*mmod.c*/
#include<stdio.h>
#include "mod1.h"
int main(void)
{
int n;
puts("enter the value of n");
scanf("%d",&n);
printf("the square of %d is :- %ld",n,sqr(n));
return 0;
}

/*this is my secondary module */
/*mod1.c*/
#include "mod1.h"

long sqr(int x)
{
return ((long)((x)*(x)));
}

/*this is my header file*/
/*mod1.h*/
long sqr(int x);
when i compile main & secondary module,every thing is ok, but as i am

trying to link them,there is a linker error i.e,undefined symbol _sqr

in mood.exe



Looks OK to me. This kind of problem relates to your compiler setup and
this group doesn''t discuss such things. So repost to a group dealing with
your compiler. But first,search the group you select for words such as make
file, IDE, project. Use the advanced search of Google groups. It is
unlikely you are the first person to have this problem.



ashu wrote:

lets look at the code given below
here i m trying to do mudular programming
/* this is my main prog.*/
/*mmod.c*/
#include<stdio.h>
#include "mod1.h"
int main(void)
{
int n;
puts("enter the value of n");
scanf("%d",&n);
printf("the square of %d is :- %ld",n,sqr(n));
return 0;
}

/*this is my secondary module */
/*mod1.c*/
#include "mod1.h"

long sqr(int x)
{
return ((long)((x)*(x)));
}

/*this is my header file*/
/*mod1.h*/
long sqr(int x);
when i compile main & secondary module,every thing is ok, but as i am

trying to link them,there is a linker error i.e,undefined symbol _sqr

in mmod.exe


Hi,

I do not see any error in your sources that can cause this problem.
It could be a problem with the way you compile and link. In particular,
check the order of the .c files.
If you are doing it with line commands or a makefile, please, post it.

Kind regards.

PS: To all readers: I known the compiler commands are OT, but it is the
best way to discard that error was in the source.


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

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