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

Linker error, but you're going to solve it with one shot

Started by draconar Oct 24, 2010 at 4:59 PM 3 replies 1k views
Original Post
draconar
draconar
Hi, guys.

I'm trying to create a header file holding constants and helper functions. These functions will get the range of an ID and other very simple calculation.

Well, so I wrote it as:

constants.h
...int checkIDrange(int ID) {	int ID_range;	if(ID >= PLAYER || ID < ENEMY)			ID_range = PLAYER;				return ID_range;}...


and then I tried to use it in a class implementation

PhysicsManager.cpp
void PhysicsManager::updateCollision() {...int entityA_ID_range = checkIDrange(entityA_ID);...}


and then VC++ 2008 gave me the following linker error:

1>PhysicsManager.obj : error LNK2005: "int __cdecl checkIDrange(int)" (?checkIDrange@@YAHH@Z) already defined in navinha003.obj
1>C:\Users\draco\Documents\Visual Studio 2008\Projects\navinha\Debug\navinha003.exe : fatal error LNK1169: one or more multiply defined symbols found

In bold you will find the error numbers. Obviously I'm not inserting the checkIDrange function correctly, but I can't figure what it is the correct way either..

skwee
skwee
Header guard?
Try
#pragma once//h file code

or
#ifndef MYH_FILE_H_#define MYH_FILE_H_//h file code#endif
I would love to change the world, but they won’t give me the source code.
Promit
Promit
Function definitions in a header need to be marked inline.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
draconar
draconar
Quote:
Original post by Promit
Function definitions in a header need to be marked inline.


I knew you guys would nail it with one shot! the question is: why the function need to be inlined? at every header file insertion is the function being defined again?

Skwee, I was using #pragma once already.
Promit
Promit
Quote:
Original post by draconar
at every header file insertion is the function being defined again?
Bingo.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

Topic Locked

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

Sign in to reply to this topic.