即使我已经包含了标题和库(这是自编译的),链接错误
Linking errors even though I've included headers and library (which is self-compiled)
我已经尝试了几个小时来让 protobuf 工作,但感觉我已经尝试了所有要尝试的事情,但我仍然无法在没有这些错误的情况下让它链接:
LNK2019 unresolved external symbol "public: __thiscall tutorial::Person_PhoneNumber::Person_PhoneNumber(void)" (??0Person_PhoneNumber@tutorial@@QAE@XZ) referenced in function "public: static class tutorial::Person_PhoneNumber * __cdecl google::protobuf::Arena::Create<class tutorial::Person_PhoneNumber>(class google::protobuf::Arena *)" (??$Create@VPerson_PhoneNumber@tutorial@@@Arena@protobuf@google@@SAPAVPerson_PhoneNumber@tutorial@@PAV012@@Z)
LNK2019 unresolved external symbol "public: __thiscall tutorial::Person::Person(void)" (??0Person@tutorial@@QAE@XZ) referenced in function "public: static class tutorial::Person * __cdecl google::protobuf::Arena::Create<class tutorial::Person>(class google::protobuf::Arena *)" (??$Create@VPerson@tutorial@@@Arena@protobuf@google@@SAPAVPerson@tutorial@@PAV012@@Z)
LNK2019 unresolved external symbol "public: __thiscall tutorial::AddressBook::AddressBook(void)" (??0AddressBook@tutorial@@QAE@XZ) referenced in function _main
LNK2019 unresolved external symbol "public: virtual __thiscall tutorial::AddressBook::~AddressBook(void)" (??1AddressBook@tutorial@@UAE@XZ) referenced in function _main
我正在使用MS Visual Studio 2015。包含库和头文件(如果我重命名 .lib 文件,它会抱怨找不到它)。
我已经尝试了 2.6.1 和 3.0.0b3(protoc 和 libprotobuf,都是自编译的和不是)。我自己编译了protoc并用它编译了示例.proto文件,但它仍然无法编译protobuf附带的示例。我已经在调试和发布模式下编译了我自己的项目和 protobuf,并且我或多或少地将 protobuf 自己的测试项目中的每个设置复制到我自己的测试项目中,但它无法编译。
感觉就像我错过了一些超级简单的东西,但是我已经用谷歌搜索了几个小时,我找不到我做错了什么。
即使是像下面这样的超级简单的文件也会生成相同的错误。
#include "example.pb.h"
int main()
{
GOOGLE_PROTOBUF_VERIFY_VERSION;
Example ex;
}
还有什么可做的/尝试的?
当你在 example.proto
上运行 protoc
时,它会生成两个文件:example.pb.h
和 example.pb.cc
。您需要将example.pb.cc
编译到程序中。
相关文章:
- std::is_base_of表示ctor编译错误
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- 如何修复sfml c++代码编译错误
- 使用 MATLAB 编码器生成C++代码:编译错误"undefined reference to `rgb2gray_tbb_real64'"
- 使用外部SDK工具链文件在VisualStudio上生成项目编译错误
- vscode下的Arduino代码出现意外编译错误
- 第三方 API 中的编译错误 - Visual Studio
- std::cout输出int时出现编译错误
- 奇怪的代码抛出编译错误模板< J,int aSize=10> C2143:语法错误:在"<"之前缺少";"
- 提升图广度优先搜索前置编译错误
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 使用带有 ref 参数的成员函数创建线程时出现编译错误
- 我在C++中遇到了这个奇怪的编译错误
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- 使用 std::enable_if 限制派生类的模板参数时出现编译错误
- 现代OpenGL和GLEW Libraray的编译错误
- C++ 编译错误:意外的类型名称"字符串":预期的表达式
- C ++程序编译错误,找不到/访问文件
- 使用直接大括号初始化时,C++ 编译错误"声明末尾的预期";"
- 为什么传递非静态成员函数会导致编译错误?