带有协议缓冲区的程序不能与MinGW-w64一起编译:“未定义的对谷歌的引用::protobuf::…”

时间:2022-09-06 07:33:51

I have installed the libprotobuf-dev=2.6.0-4 and protobuf-compiler=2.6.0-4 packages from Debian Jessie repository. Now I'm trying to compile a program that use the 'addressbook.proto' file from the Google Developers example with the MinGW-w64 compiler. I'm using Ubuntu 14.04.

我已经在Debian Jessie存储库中安装了libprotobuf-dev=2.6.0-4和protobuf-compiler=2.6.0-4包。现在我正在尝试编译一个使用“addressbook”的程序。proto的文件来自谷歌开发人员示例,其中有MinGW-w64编译器。我使用Ubuntu 14.04。

With this command the program works:

通过这个命令,程序可以工作:

$ g++ main.cpp addressbook.pb.cc -lprotobuf

But I want to compile for Windows too.

但是我也想为Windows编译。

I added the symlink: /usr/include/google -> /usr/i686-w64-mingw32/include/google.

我添加了符号链接:/usr/include/google -> /usr/i686-w64-mingw32/include/谷歌。

$ i686-w64-mingw32-g++ main.cpp addressbook.pb.cc -lprotobuf
/usr/bin/i686-w64-mingw32-ld: cannot find -lprotobuf
collect2: error: ld returned 1 exit status

With the library location still not working:

由于图书馆的位置仍然不工作:

$ i686-w64-mingw32-g++ -L /usr/lib/i386-linux-gnu/ main.cpp addressbook.pb.cc -lprotobuf
/tmp/ccB1VJyR.o:main.cpp:(.text$_ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv[__ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv]+0x7): undefined reference to `google::protobuf::internal::empty_string_'
/tmp/ccB1VJyR.o:main.cpp:(.text$_ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv[__ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv]+0x2f): undefined reference to `google::protobuf::internal::empty_string_'
/tmp/ccPz4uiI.o:addressbook.pb.cc:(.text+0x78): undefined reference to `google::protobuf::DescriptorPool::generated_pool()'
/tmp/ccPz4uiI.o:addressbook.pb.cc:(.text+0x87): undefined reference to `google::protobuf::DescriptorPool::FindFileByName(std::string const&) const'
...

1 个解决方案

#1


0  

libprotobuf-dev contains library headers and pre-built binaries for your system. If you are cross-compiling you need to compile library from sources to target system as well. Something like "./configure CC=i686-w64-mingw32-g++" in library sources directory should do the job.

libprotobuf-dev为系统包含库头和预先构建的二进制文件。如果交叉编译,则需要从源到目标系统编译库。像”。/configure CC=i686-w64-mingw32-g+ " in library sources目录应该可以完成这项工作。

#1


0  

libprotobuf-dev contains library headers and pre-built binaries for your system. If you are cross-compiling you need to compile library from sources to target system as well. Something like "./configure CC=i686-w64-mingw32-g++" in library sources directory should do the job.

libprotobuf-dev为系统包含库头和预先构建的二进制文件。如果交叉编译,则需要从源到目标系统编译库。像”。/configure CC=i686-w64-mingw32-g+ " in library sources目录应该可以完成这项工作。