# Unresolved externals using namespace in C++

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

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites

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.

##### Share on other sites
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.

##### Share on other sites

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

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633680
• Total Posts
3013302
×