Jump to content
  • Advertisement
Sign in to follow this  
draconar

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

This topic is 2852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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..

Share this post


Link to post
Share on other sites
Advertisement
Header guard?
Try

#pragma once
//h file code

or

#ifndef MYH_FILE_H_
#define MYH_FILE_H_
//h file code
#endif

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by draconar
at every header file insertion is the function being defined again?
Bingo.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!