c++ - C++ 中的 Protobuffers 和错误 LNK2019 : unresolved external symbol

标签 c++ visual-studio-2012 protocol-buffers

我是 c++ 和 visual studio 2012 的新手,所以问题可能出在屏幕和椅子之间。我执行了以下步骤;

  1. 我制作了一个带有选项 optimize_for = LITE_RUNTIME 的简单原型(prototype)文件
  2. 用protoc创建匹配的h和c文件
  3. 编译库 libprotobuf-lite.lib
  4. 创建了一个新的控制台 Visual Studio 2012 项目。
  5. 复制我的单一源文件所在的 libprotobuf-lite.lib。
  6. 创建了一个名为 protobuffers 的新文件夹
  7. 将 c、h 和 google 目录从 protobuffers src 目录复制到 protobuffers 文件夹
  8. 将 protobuffers 文件夹添加为附加包含目录
  9. 通过 Additional Dependencies 将库文件添加到链接器
  10. 编译了如下源文件;

    #include <iostream>
    #include "protobuffers\genome.pb.h"
    
    int main()
    {
       genomeMessage::Genome genome;
       return 0;
    }
    
  11. 卡住...我收到以下错误;

    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
    

所以我知道它不是丢失的 lib 文件,因为如果我移动 lib 文件,链接器会提示找不到它。问题是我不知道如何解决这个问题……有人吗?

最佳答案

根据这条消息:

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

声明 genomeMessage::Genome::Genome(void)genomeMessage::Genome::~Genome(void) 的源文件不是您项目的一部分.

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

关于c++ - C++ 中的 Protobuffers 和错误 LNK2019 : unresolved external symbol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13399141/

相关文章:

visual-studio - 在 Visual Studio 2012 中使用 MSBuild PublishProfile 时的 MSDeploy 跳过规则

sql - 不支持将Azure数据库导入本地

c++ - 异常抛出 : Access violation reading location in VS 2012.(在 VS2010 中没有)

c++ - 如何关闭应用程序,包括所有打开的子窗口,MFC

c++ - 如何使 C++ 程序跨编译器工作

c++ - 引发导致代码崩溃,而不仅仅是退出

c++ - 为什么 is_swappable 和 is_nothrow_swappable 不包含在 C++11 中?

go - 如何在go模块中使用生成的protobuf包?

c++ - 谷歌 Protocol Buffer 是否支持序列化前的大小计算?

java - Avro 与 Protobuf 性能对比