Re: problem in modular programing



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*
==============


.



Relevant Pages

  • Re: It Pays to Enrich Your C Skills
    ... Check if you can score a perfect 10 (without using a compiler). ... int main{ ... struct bitfield { ... out if it is a negative integer constant or a constant expression ...
    (comp.lang.c.moderated)
  • OT: Re: Perl Peeves
    ... I see the result of a test being used as an int. ... the compiler just assumed you knew what you were doing ... introduced to the language later, so void * was unheard of in most code. ... This didn't mean bool was special, declaring it just signaled to the ...
    (comp.lang.perl.misc)
  • Re: OT: Re: Perl Peeves
    ... when I see the result of a test being used as an int. ... compiler just assumed you knew what you were doing and would ... This didn't mean bool was special, declaring it just signaled to the ... What "normalization of bool results is built into the compiler"? ...
    (comp.lang.perl.misc)
  • Re: [CodeGallery] MFC MD5 Calculator
    ... Then when they added types, internally, the compiler still thought they were int values, ... ANSI standard began to emerge that the language design ...
    (microsoft.public.vc.mfc)
  • Re: First steps on overloading
    ... where the operand manipulation code is located, ... very many additions and changes to the language semantics. ... Allowing int + date, as well as date + int (although the former seems a bit ... compiler would reorder the operands. ...
    (comp.lang.misc)