• Create Account

## Unresolved externals using namespace in C++

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1rocklobster  Members

415
Like
0Likes
Like

Posted 30 March 2012 - 10:47 AM

Hi,

I'm getting unresolved external symbols when using classes which are apart of a namespace (located in a separate folder).

This is a stripped down version main class i've written thats apart of its own VS2010 project.

main.cpp
#include <Engine/input.h>
#include <Engine/graphics.h>
#include <Engine/sound.h>

using namespace Engine;

int main()
{
InputManager* input = new InputManager();
input->initialise();

etc.
}

It is including classes which are in a different folder and defined like so...


#ifndef INPUTMGR_H
#define INPUTMGR_H

namespace Engine
{
class InputManager
{
void initialize();
// rest of functions
};
}
#endif

and the cpp would be like..

#include "InputManager.h"
namespace Engine
{
void InputManager::initialise()
{
// setup keyboard and mouse etc
}
}

I'm getting unresolved external errors to the functions that i call such as initialise(). Now i have told visual studio to look for source and include directories to this folder (because i can include and compile them so it works) but i'm still getting these errors. I should also add that putting the source code in the same folder as main.cpp works fine, but i'd like to not do this because that means each test program will have a dated copy of the engine (That is still currently in progress).

Any one got any ides or a better solution to what i'm trying to achieve?

Much appreciated,

- rocklobster

### #2ApochPiQ  Moderators

21386
Like
0Likes
Like

Posted 30 March 2012 - 05:11 PM

The code you posted works fine, assuming you set up your project correctly to actually have the .cpp file in the project.

I'm not really clear on what the difference is between what you posted and your actual situation, so divining the true cause of your compile errors is going to be tricky at best and more likely impossible.
Wielder of the Sacred Wands

### #3SiCrane  Moderators

11522
Like
0Likes
Like

Posted 30 March 2012 - 07:06 PM

You mentioned that you're using subdirectories. Do you have source files with the same name, but in different directories? If so, MSVC may be assigning the same name and location for the generated object files for those source files, which means effectively that only one of them is being compiled.

### #4ApochPiQ  Moderators

21386
Like
0Likes
Like

Posted 30 March 2012 - 08:56 PM

You mentioned that you're using subdirectories. Do you have source files with the same name, but in different directories? If so, MSVC may be assigning the same name and location for the generated object files for those source files, which means effectively that only one of them is being compiled.

I can't say for sure that this isn't a possibility, but I do this all the time (Foo.cpp in /Some/Path and Foo.cpp in /Other/Path) and it works fine. MSVC is smart enough to number the .obj files so that they don't collide, at least in my experience.
Wielder of the Sacred Wands

### #5SiCrane  Moderators

11522
Like
0Likes
Like

Posted 31 March 2012 - 07:30 AM

Really? I just double checked to see if MSVC 2010 was smart enough to do this and it wasn't. It generates a "LNK4042: object specified more than once; extras ignored" unless you manually number the object files or stick them in subdirectories yourself.

### #6wqking  Members

756
Like
0Likes
Like

Posted 31 March 2012 - 08:12 AM

Really? I just double checked to see if MSVC 2010 was smart enough to do this and it wasn't. It generates a "LNK4042: object specified more than once; extras ignored" unless you manually number the object files or stick them in subdirectories yourself.

I also remember VC will put all .obj files to one directory, so the source files with same names will override each other's .obj file, no matter which directory the source files are in.
Anyway, I always use unique source file name to avoid trouble.

Here also has some discussion on that issue,
http://stackoverflow...lename-conflict
And here,
http://connect.microsoft.com/VisualStudio/feedback/details/361228/visual-c-compilers-only-one-file-of-two-with-the-same-name

Edited by wqking, 31 March 2012 - 08:13 AM.

http://www.cpgf.org/
cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.