0

ProjectAAA.obj : error LNK2001: unresolved external symbol "public: __thiscall X::ClassEvent::ClassEvent(unsigned int)" (??0ClassEvent@X@@QAE@I@Z)

boost::shared_ptr<ClassEvent> bcfEvent(new ClassEvent((unsigned int) 10));

I have defined ClassEvent::ClassEvent(unsigned int) and have no idea how to fix this LINK errors.

Any suggestion is appreciated.

Thank you

MORE INFO:

1>ProjectAAA.obj : error LNK2019: unresolved external symbol "public: __thiscall APP::X::ClassEvent::ClassEvent(unsigned int)" (??0ClassEvent@X@APP@@QAE@I@Z) referenced in function "private: class std::vector,class std::allocator > > __thiscall APP::X::ProjectAAA::GenerateEvents(class std::map > > const &)" (?GenerateEvents@ProjectAAA@X@APP@@AAE?AV?$vector@V?$shared_ptr@VClassEvent@X@APP@@@boost@@V?$allocator@V?$shared_ptr@VClassEvent@X@APP@@@boost@@@std@@@std@@ABV?$map@VDate@APP@@IUEventAttributesMapCompare@ProjectAAA@X@2@V?$allocator@U?$pair@$$CBVDate@APP@@I@std@@@std@@@5@@Z)

Now I have completely isolated the error:

1>ProjectAAA.obj : error LNK2019: unresolved external symbol "public: __thiscall APP::X::ClassEvent::ClassEvent(unsigned int)" (??0ClassEvent@X@APP@@QAE@I@Z) referenced in function "private: void __thiscall APP::X::ProjectAAA::TestGenerateEvents(void)" (?TestGenerateEvents@ProjectAAA@X@APP@@AAEXXZ)

q0987
  • 34,938
  • 69
  • 242
  • 387
  • 1
    Might be helpful: http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – chris Oct 10 '12 at 18:28
  • 1
    Need more information. Show a minimal but complete example that produces this error message. – John Dibling Oct 10 '12 at 18:29
  • simple code works fine. I have a huge project and I am not able to use any functions defined in the class of ClassEvent. Compilation is fine but link always gives errors. – q0987 Oct 10 '12 at 18:37
  • Make sure there is only one file named ClassEvent.cpp in the whole project. If this is not the case, the generated obj files will collide and thus symbols will be missing. – Karel Petranek Oct 10 '12 at 18:40
  • I have two ClassEvent.cpp in my solution files. One in ProjectBBB and the other in ProjectAAA. I use different namespace to separate them. One is in APP {} and the other is in APP::X{}. I have similar cases for other files without any problems though. – q0987 Oct 10 '12 at 18:45
  • 1
    Did you implement your `ClassEvent::ClassEvent(unsigned int)` inside namespace `X`? It doesn't seem to ba nested inside `APP::X` according to the error message. – Dietmar Kühl Oct 10 '12 at 18:56
  • yes. I did it correctly inside APP::X – q0987 Oct 10 '12 at 19:01
  • Don't just talk about your code, show us your code. – Bart Oct 10 '12 at 19:07
  • Small example doesn't involve the LNK error. I only see it when I build the whole solution. – q0987 Oct 10 '12 at 19:09

3 Answers3

1

Your problem is having two ClassEvent.cpp files in your solution. When VC++ compiles your solution, it outputs all obj files in one directory and thus generates two ClassEvent.obj files. Whichever cpp is compiled later overwrites the former. This causes symbols from the first one being lost and invisible to the linker.

You can fix this issues by opening properties of one of the files, choosing C/C++ -> Output Files -> Object File Name and changing it to some non-colliding value (such as ClassEvent2.obj).

I believe this is a bug in Visual Studio but it hasn't been addressed in last 4 versions and is therefore likely to stay.

Karel Petranek
  • 15,005
  • 4
  • 44
  • 68
1

After multiple testing, I found the solution.

Someone in the team excludes the ClassEvent.CPP from the project!!!

q0987
  • 34,938
  • 69
  • 242
  • 387
0

In my case all begun working correctly after I changed the build architecture from x64 to x86 bit. Two days ago I had the same problem. This was caused by deploying my program to another computer. For some reason, which I don't know, the architecture settings have changed from x86 (as I write) to x64. PS. I used Visual Studio 2015;

Andrew Kachalin
  • 229
  • 2
  • 13