4

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;

  1. I made a simple proto file with the option optimize_for = LITE_RUNTIME
  2. Create the matching h and c files with protoc
  3. Compiled the library libprotobuf-lite.lib
  4. Created a new console Visual Studio 2012 project.
  5. Copied the libprotobuf-lite.lib where my single source file is.
  6. Created a new folder named protobuffers
  7. Copied the c, h and the google directory from the protobuffers src directory to the protobuffers folder
  8. Added the protobuffers folder as an Additional Include Directory
  9. Added the library file to the linker through Additional Dependencies
  10. Compiled the following source file;

    #include <iostream>
    #include "protobuffers\genome.pb.h"
    
    int main()
    {
       genomeMessage::Genome genome;
       return 0;
    }
    
  11. 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?

Aktaeon
  • 189
  • 2
  • 14
  • If you right click "Genome" in genomeMessage::Genome and select "Go to Symbol" are you able to see the symbol defined in the header file? If so, then the selected answer is valid. If not, then the selected answer is not (for this particular case) and it is possible you need to export your symbol possibly using LIBPROTOBUF_EXPORT – sitting-duck Oct 25 '19 at 21:21

1 Answers1

6

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.

Josh Kelley
  • 56,064
  • 19
  • 146
  • 246