Re: .cpp linking problem

Top Page
Attachments:
Message as email
+ (text/plain)
+ (text/html)
+ (text/plain)
Delete this message
Reply to this message
Author: Jon M. Hanson
Date:  
To: unixprgrmr01, Main PLUG discussion list
Subject: Re: .cpp linking problem
It sounds like you're getting the same header file included multiple
times. If you look at the system header files you will see something
like the following:

#ifndef _STDIO_H
#define _STDIO_H

[Header file code here]

#endif

So the first time stdio.h is included the header file code will be
compiled. The second time something tries to include stdio.h, _STDIO_H
is now defined so the header code is skipped thus avoiding the
multiple includes. Try this with your header file(s) to see if it helps.

---
Jon M. Hanson (N7ZVJ)
Weblog: http://the-hansons-az.net/wordpress/
Homepage: http://the-hansons-az.net/
Jabber IM:



On Feb 14, 2009, at 8:03 PM, wrote:

> I am trying to link library xy.a composed of x.o containing function
> x() and y.o containing function y() with d.o giving executable d
>
> I call both x() and y() from d.cpp. When I comment out the function
> call to y() in d.cpp it links just fine with library xy.a giving
> executable d BUT when I uncomment the function call to y() I get
> duplicate variable declaration errors.
>
> Note that I need x.o and y.o in a library because I also link them
> with e.o to give executable e . Both x() and y() are called from
> both d and e executables.
>
> I use the same custom include files in x.o y.o d.o and e.o. I am
> getting duplicate variable errors from the variables declared in
> these custom include files.
>
> I also include standard include files such as <stdio.h> and <math.h>
> etc. etc. in all 4 .o's but I don't get duplicate variable errors
> from these.
>
> I am #ifndef ing the entire include file just as is done with
> <stdio.h> etc. What am I doing wrong, that at link time I get
> duplicate variable errors?
>
> Thanks for your help!
>
> --
> Best Regards,
> Lynn P. Tilby
> Ph: 480 632-8635
>
>
> ---------------------------------------------------
> PLUG-discuss mailing list -
> To subscribe, unsubscribe, or to change your mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss