Re: problem in modular programing
- From: "pemo" <usenetmeister@xxxxxxxxx>
- Date: Wed, 22 Feb 2006 15:58:45 -0000
tmp123 wrote:
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.
Sounds like you're possibly using Visual C?
The code looks ok, btw, you don't need to include mod1.h in mod1.c - but
it's doing no harm.
If you've got the MS compiler set up to run from a command prompt, then this
should work ...
cl mmod.c mod1.c [output in mmod.exe]
Or, if you just want to use the linker ...
link mmod.obj mod1.obj [output in mmod.exe]
To set up the Microsoft compiler so that it works from a command prompt,
open a command prompt, navigate to ...\Microsoft Visual Studio\VC98\Bin and
run vcvars32
--
==============
*Not a pedant*
==============
.
- Follow-Ups:
- Re: problem in modular programing
- From: Pedro Graca
- Re: problem in modular programing
- From: CBFalconer
- Re: problem in modular programing
- From: Chris Dollin
- Re: problem in modular programing
- From: tmp123
- Re: problem in modular programing
- References:
- problem in modular programing
- From: ashu
- Re: problem in modular programing
- From: tmp123
- problem in modular programing
- Prev by Date: Re: Creating a packet for RAW socket transfer
- Next by Date: Re: Casting a pointer to an int and back
- Previous by thread: Re: problem in modular programing
- Next by thread: Re: problem in modular programing
- Index(es):
Relevant Pages
|