?
Solved

Redefined symbols on link

Posted on 2003-03-09
1
Medium Priority
?
209 Views
Last Modified: 2012-05-05
Hello,

I have a VC6 project I'm trying to compile however I get a ton of "already defined" messages on linking. I am pretty sure this is due to including files where they shouldn't be so can someone give me a rundown on where includes should go?

Here are the basics of the includes by file:

driver.cpp
#include "..\state.h"

state.cpp
#include "state.h"
#include "packet.h"

player.cpp
#include "player.h"
#include "deck.h"

deck.h

hopper.h
#include "deck.h"

player.h

state.h

Every function I call in player, hopper or deck results in something like this:
state.obj : error LNK2005: "public: __thiscall ADeck::ADeck(void)" (??0ADeck@@QAE@XZ) already defined in StateTester.obj

Thanks for the help
0
Comment
Question by:jkelly061597
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 15

Accepted Solution

by:
efn earned 200 total points
ID: 8100863
Hi jkelly,

It's impossible to tell exactly what the problem is from the information you have provided, but I will give you some general information that may help.

Something like this:

extern int f();

is a "declaration."  It tells the compiler that the function will exist somewhere, but it doesn't tell the compiler what should happen when the function is called.

Something like this:

int f()
{
return 0;
}

is a "definition."  It tells the compiler what the function should do, so when the compiler sees one of these, it generates some executable code for the function.

In general, you want to arrange things so each function is defined only once in all the object files you link.  (If you define it twice, the linker doesn't know which copy to use to resolve references.)  Normally, you put the definition in a .cpp file and you put a declaration in a .h file.  Then any other file that needs to call the function #includes the .h file.  So code for the function is only generated when you compile the .cpp file.

Your problem could be caused by having definitions in header files.  If you define the ADeck constructor in a header file and include that header file in more than one source file, you will get a multiple reference error as you have seen.  The fix is to define the functions in .cpp files and only declare them, not define them, in header files.

--efn
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question