简体   繁体   English

c ++中的Protobuffers和错误LNK2019:未解析的外部符号

[英]Protobuffers in c++ and error LNK2019: unresolved external symbol

I am new to c++ and visual studio 2012 so probably the problem is between the screen and the chair. 我是c ++和visual studio 2012的新手,所以可能问题出在屏幕和椅子之间。 I performed the following steps; 我执行了以下步骤;

  1. I made a simple proto file with the option optimize_for = LITE_RUNTIME 我使用选项optimize_for = LITE_RUNTIME创建了一个简单的proto文件
  2. Create the matching h and c files with protoc 使用protoc创建匹配的h和c文件
  3. Compiled the library libprotobuf-lite.lib 编译了库libprotobuf-lite.lib
  4. Created a new console Visual Studio 2012 project. 创建了一个新的控制台Visual Studio 2012项目。
  5. Copied the libprotobuf-lite.lib where my single source file is. 复制我的单个源文件所在的libprotobuf-lite.lib。
  6. Created a new folder named protobuffers 创建了一个名为protobuffers的新文件夹
  7. Copied the c, h and the google directory from the protobuffers src directory to the protobuffers folder 将c,h和google目录从protobuffers src目录复制到protobuffers文件夹
  8. Added the protobuffers folder as an Additional Include Directory 添加了protobuffers文件夹作为附加包含目录
  9. Added the library file to the linker through Additional Dependencies 通过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. 所以我知道它不是一个缺少的lib文件,因为如果我移动lib文件,链接器会抱怨它无法找到它。 The problem is that I have no clue how to fix this ... anyone? 问题是我不知道如何解决这个问题......任何人?

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. 声明genomeMessage::Genome::Genome(void)genomeMessage::Genome::~Genome(void) genomeMessage::Genome::Genome(void)的源文件不是您项目的一部分。

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. 特别是,听起来您还没有将genome.pb.cc文件(由Protocol Buffers编译器创建)添加到您的项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM