Skip to main content
GameDev.net gamedev.net
🔒 Locked

linking: multiple definition

Started by slip Jan 27, 2003 at 5:44 AM 1 replies 400+ views
Original Post
slip
slip
I''ve got two source files including the same header file, and within the header file I declare some variables, after compiling when ''ld'' tries to link the object files together it complains about the variables being declared twice. What can I do to solve this problem? Is there a special way to declare the variables? Thanks in advance slip
www.ice-d.com
Koen
Koen
The header file is included in both sourcefiles. This means the variable definitions exist twice. Declare you global vars in one and only one sourcefile. If you want to use them in another source (or header file) use the extern keyword like this:

test.cpp:

int aVar=5;//this is the real declaration

someheader.h or someSource.cpp:

extern int aVar;//this means aVar exists somewhere else

[edited by - Koen on January 27, 2003 7:42:47 AM]
slip
slip
Thanks... I just found the solution from an article here too. =)

slip
www.ice-d.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.