在MinGW中安装Protobuf开发库

Installing Protobuf Development Libraries in MinGW

本文关键字:开发 Protobuf 安装 MinGW      更新时间:2023-10-16

我从github上的源代码中安装了Protobuf。

当我尝试编译我的c++程序时,我得到错误:

CMakeFiles/nxcore_interface.dir/main.cpp.o:main.cpp:(.rdata$.refptr._ZN6google8protobuf8internal13empty_string_E[.refptr._ZN6google8protobuf8internal13empty_string_E]+0x0): undefined reference to `google::protobuf::internal::empty_string_'
collect2: error: ld returned 1 exit status

我发现一些东西表明开发库不存在:

带协议缓冲区的程序不要编译MinGW-w64: "undefined reference to google::protobuf::…"

我已经包含了-lprotobuf编译器标志。

经过一番搜索,我确定我需要使用libprotobuf-dev,但我很难找到它。

有没有人知道在哪里得到它,或者是其他错误?

您应该使用pkg-config编译您的应用程序。

g++ my_program.cpp `pkg-config --cflags --libs protobuf`

如果您没有pkg-config,您应该找到库路径并使用-L选项设置它们。如:

g++ my_program.cpp -L/usr/local/protobuf/lib -lprotobuf