- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在尝试使用 Protocol Buffers 2.6.1 和 GNU GCC 5.1.0(在 Ubuntu 14.10 上)构建简单的测试应用程序,但出现以下错误:
/home/ragnar/cpp-tools/gcc-linux/bin/g++ -c "/home/ragnar/cpp-projects/gprotobuf_test/main.cpp" -g -O0 -Wall -o ./Debug/main.cpp.o -I. -I/home/ragnar/cpp-tools/libs/linux64/protobuf/include -I.
/home/ragnar/cpp-tools/gcc-linux/bin/g++ -c "/home/ragnar/cpp-projects/gprotobuf_test/messages.pb.cc" -g -O0 -Wall -o ./Debug/messages.pb.cc.o -I. -I/home/ragnar/cpp-tools/libs/linux64/protobuf/include -I.
/home/ragnar/cpp-tools/gcc-linux/bin/g++ -o ./Debug/gprotobuf_test @"gprotobuf_test.txt" -L. -L/home/ragnar/cpp-tools/libs/linux64/protobuf/lib -lprotobuf
./Debug/main.cpp.o: In function google::protobuf::internal::GetEmptyStringAlreadyInited[abi:cxx11]():
/home/ragnar/cpp-tools/libs/linux64/protobuf/include/google/protobuf/generated_message_util.h:80:
undefined reference to google::protobuf::internal::empty_string_[abi:cxx11]
/home/ragnar/cpp-tools/libs/linux64/protobuf/include/google/protobuf/generated_message_util.h:81:
undefined reference to google::protobuf::internal::empty_string_[abi:cxx11]
./Debug/messages.pb.cc.o: In function protobuf_AssignDesc_messages_2eproto():
/home/ragnar/cpp-projects/gprotobuf_test/messages.pb.cc:32:
undefined reference to google::protobuf::DescriptorPool::FindFileByName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const
./Debug/messages.pb.cc.o: In function protobuf_AddDesc_messages_2eproto():
/home/ragnar/cpp-projects/gprotobuf_test/messages.pb.cc:83:
undefined reference to google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&))
./Debug/messages.pb.cc.o: In function my_message::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*):
/home/ragnar/cpp-projects/gprotobuf_test/messages.pb.cc:187:
undefined reference to google::protobuf::internal::WireFormatLite::ReadString(google::protobuf::io::CodedInputStream*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)
./Debug/messages.pb.cc.o: In function my_message::SerializeWithCachedSizes(google::protobuf::io::CodedOutputStream*) const:
/home/ragnar/cpp-projects/gprotobuf_test/messages.pb.cc:247:
undefined reference to google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)
./Debug/messages.pb.cc.o: In function google::protobuf::internal::WireFormatLite::WriteStringToArray(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned char*):
/home/ragnar/cpp-tools/libs/linux64/protobuf/include/google/protobuf/wire_format_lite_inl.h:749:
undefined reference to google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned char*)
./Debug/messages.pb.cc.o:(.rodata._ZTV10my_message[_ZTV10my_message]+0x20):
undefined reference to google::protobuf::Message::GetTypeName[abi:cxx11]() const
./Debug/messages.pb.cc.o:(.rodata._ZTV10my_message[_ZTV10my_message]+0x40):
undefined reference to google::protobuf::Message::InitializationErrorString[abi:cxx11]() const
collect2: error: ld returned 1 exit status
gprotobuf_test.mk:93: recipe for target "Debug/gprotobuf_test" failed
make[1]: *** [Debug/gprotobuf_test] Error 1
make[1]: Leaving directory "/home/ragnar/cpp-projects/gprotobuf_test"
Makefile:4: recipe for target "All" failed
make: *** [All] Error 2
/home/ragnar/cpp-tools/libs/linux64/protobuf/lib 包含以下库:
libprotobuf.a
libprotobuf.so.9.0.1
libprotobuf-lite.a
libprotobuf-lite.so.9.0.1
libprotoc.a
libprotoc.so.9.0.1
这是简单的 messages.proto 文件:
option java_package = "my.package";
message my_message {
required string word = 1;
required uint32 number = 2;
}
以及我正在尝试使用的代码:
#include <iostream>
#include <vector>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include "messages.pb.h"
std::vector<unsigned char> encode( google::protobuf::Message & msg )
{
std::vector<unsigned char> data( msg.ByteSize() +
google::protobuf::io::CodedOutputStream::VarintSize32( msg.ByteSize() ) );
google::protobuf::io::ArrayOutputStream array_out( &data[0], data.size() );
google::protobuf::io::CodedOutputStream coded_out( &array_out );
coded_out.WriteVarint32( msg.ByteSize() );
msg.SerializeToCodedStream( &coded_out );
return data;
}
void decode( const std::vector<unsigned char> & data, google::protobuf::Message & msg )
{
google::protobuf::io::ArrayInputStream array_in( &data[0] , data.size() );
google::protobuf::io::CodedInputStream coded_in( &array_in );
google::protobuf::uint32 size;
coded_in.ReadVarint32( &size );
google::protobuf::io::CodedInputStream::Limit msg_limit = coded_in.PushLimit( size );
msg.ParseFromCodedStream( &coded_in );
coded_in.PopLimit( msg_limit );
}
int main(int argc, char **argv)
{
my_message in_msg;
in_msg.set_word( \"blah blah\" );
in_msg.set_number( 123 );
std::vector<unsigned char> data = encode( in_msg );
my_message out_msg;
decode( data, out_msg );
std::cout << \"word: \" << out_msg.word() << \" number: \" << out_msg.number() << std::endl;
return 0;
}
Gcc 是从源代码构建的,具有以下选项:
--enable-64bit --enable-32bit --enable-languages=c,c++ --enable-multilib
--disable-nls --enable-threads=posix --enable-checking=release
--enable-lto --enable-multiarch --with-multilib-list=m32,m64,mx32
--with-tune=generic --enable-shared --with-glibc-version=2.13
--enable-libstdcxx-time=rt
并且 Protobuf 是从源代码构建的,具有以下选项:
--enable-64it --disable-32bit --enable-shared CXXFLAGS=-m64 -DNDEBUG LDFLAGS=-m64
任何帮助将不胜感激。
最佳答案
我怀疑这是 C++ ABI 问题。 std::string
的 ABI 在 GCC 5 中已更改(与 C++11 要求相关,但即使您不使用 C++11 也适用)。见:
https://gcc.gnu.org/gcc-5/changes.html#libstdcxx
如果 libprotobuf 是使用 GCC 4.x 或更早版本构建的,但您的应用程序是使用 GCC 5 构建的,那么您会发现问题,因为 libprotobuf 在其界面中使用 std::string
。你有两个选择:
-D_GLIBCXX_USE_CXX11_ABI=0
构建您的应用程序。这将强制 GCC 使用旧的 ABI 版本。关于c++ - 对 google::protobuf::internal::empty_string_[abi:cxx11] 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30124264/
我只是有一个更琐碎的问题。 为什么undefined == undefined 返回true,而undefined >= undefined 为false? undefined 等于 undefine
用PHP 7.2编写套接字服务器。根据Firefox 60中的“网络”选项卡,服务器的一些HTTP响应的第一行随机变为undefined undefined undefined。因此,我尝试记录套接字
在 JavaScript 中这是真的: undefined == undefined 但这是错误的: undefined <= undefined 起初我以为<=运算符包含第一个,但我猜它试图将其转换
在回答这个问题 (Difference between [Object, Object] and Array(2)) 时,我在 JavaScript 数组中遇到了一些我以前不知道的东西(具有讽刺意味的
来自https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/of , Note: thi
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
当我添加 到我的 PrimeFaces Mobile 页面,然后我在服务器日志中收到以下警告 WARNING: JSF1064: Unable to find or serve resource, u
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我是一名优秀的程序员,十分优秀!