Protobuffers in c++ and error LNK2019: unresolved external symbol
c++, protocol-buffers, visual-studio-2012
Solution
According to this message:
1>Source.obj : error LNK2019: unresolved external symbol "public: __cdecl genomeMessage::Genome::Genome(void)" (??0Genome@genomeMessage@@QEAA@XZ) referenced in function main
1>Source.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl genomeMessage::Genome::~Genome(void)" (??1Genome@genomeMessage@@UEAA@XZ) referenced in function main
the source file that declares `genomeMessage::Genome::Genome(void)` and `genomeMessage::Genome::~Genome(void)` is not part of your project.
In particular, it sounds like you haven't added the `genome.pb.cc` file (which is created by the Protocol Buffers compiler) to your project.
Problem
I am new to c++ and visual studio 2012 so probably the problem is between the screen and the chair. I performed the following steps; - I made a simple proto file with the option optimize_for = LITE_RUNTIME - Create the matching h and c files with protoc - Compiled the library libprotobuf-lite.lib - Created a new console Visual Studio 2012 project. - Copied the libprotobuf-lite.lib where my single source file is. - Created a new folder named protobuffers - Copied the c, h and the google directory from the protobuffers src directory to the protobuffers folder - Added the protobuffers folder as an Additional Include Directory - Added the library file to the linker through Additional Dependencies Compiled the following source file; ``` #include <iostream> #include "protobuffers\genome.pb.h" int main() { genomeMessage::Genome genome; return 0; } ``` Stuck... I get the following error; ``` 1>Source.obj : error LNK2019: unresolved external symbol "public: __cdecl genomeMessage::Genome::Genome(void)" (??0Genome@genomeMessage@@QEAA@XZ) referenced in function main 1>Source.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl genomeMessage::Genome::~Genome(void)" (??1Genome@genomeMessage@@UEAA@XZ) referenced in function main 1>C:\Projects\testproto\x64\Debug\testproto.exe : fatal error LNK1120: 2 unresolved externals ``` So I know it is not a missing lib file because if I move the lib file the linker complains that it can't find it. The problem is that I have no clue how to fix this ... anyone?