RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 1623 | Replies: 3
Reply
Join Date: Jun 2005
Posts: 23
Reputation: alone2005 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
alone2005's Avatar
alone2005 alone2005 is offline Offline
Newbie Poster

compile and link error problem (gcc)

  #1  
Jul 20th, 2005
Simplify my problem I put a short version of code here,
first header file:
namespace xxx{
class util{
public:                                     
	static int MAX_PATH ;
	util();
	static void init();
	static void do(void);
}; //end class
int util::MAX_PATH ;
}

cpp file:
namespace xxx{
util::util(){
	init();
}
void util::init(){
	MAX_PATH = 100;
}
void do(){
        //use MAX_PATH somewhere
}
}

my problem is I can compile them to generate .o file correctly, but whenever I link them
with other program, i got:
...multiple definition of MAX_PATH...

think hard but found no reason, anyone can help? thanks in advance.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,765
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: compile and link error problem (gcc)

  #2  
Jul 21st, 2005
http://www.parashift.com/c++-faq-lit...html#faq-10.11

Moral: don't put the definition in the header.


[edit]And do is a keyword.
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
Reply With Quote  
Join Date: Jun 2005
Posts: 23
Reputation: alone2005 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
alone2005's Avatar
alone2005 alone2005 is offline Offline
Newbie Poster

Re: compile and link error problem (gcc)

  #3  
Jul 21st, 2005
Thanks, actually i thought I used #ifndef so this would not be included more than
once.
for the do( ), i just use it to simplify code, more like doSomething( )


Originally Posted by Dave Sinkula
http://www.parashift.com/c++-faq-lit...html#faq-10.11
Moral: don't put the definition in the header.

[edit]And do is a keyword.
Reply With Quote  
Join Date: Apr 2004
Posts: 3,765
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: compile and link error problem (gcc)

  #4  
Jul 21st, 2005
Originally Posted by alone2005
Thanks, actually i thought I used #ifndef so this would not be included more than once.
Right -- per module. Each module then has its own copy and this upsets the linker.
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:12 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC