I have a VC++ solution with multiple projects and multiple namespaces. Each project has its own namespace, and some projects have multiple namespaces.
Sometimes, when I reference an object from another project I will end up with "unresolved external symbol" errors even though I #included the header file and referenced the object through it's namespace (Namespace::object). In order to get rid of the linker errors I have to also #include the cpp file, then I get warnings that the symbol was defined twice.
This is very hackish and I don't like hackish.
I know that I need to go through and look at all the include dependencies, since something's obviously screwed up, but I haven't been 开发者_如何学Cable to find any major problems as of yet.
In the mean time, does anyone have any suggestions for anything obvious to check or any common causes to this problem?
"unresolved external symbols" are linker errors. And linking doesn't care about what gets #included (not unless there are #pragmas involved). All linking cares about is what you explicitly state you're linking with.
Those other projects you're trying to use must produce a library or something when you compile them, right? You should link to those in your project settings.
If you are using Visual C++, Go to your project properties, under Linker > Input
, you should add the compiled .lib
file of the project you are depending on.
Like others have stated, the compilation unit you are missing has nothing to do with files you #include
(which are only relevant for compilation, not linkage)
Linking object files is not done using #include
preprocessor commands, but through VC++ itself or (non-standard) #pragma
commands..
精彩评论