tar -xvf protobuf-cpp-3.6.1.tar.gz cd protobuf-3.6.1 ./configure --disable-shared CXXFLAGS="-fPIC" make -j8
tips: we compile static library with --disable-shared CXXFLAGS="-fPIC". 编译动态库dll/so的时候,如果依赖static library(比如profobuf),那么static library编译的时候需要加上-fPIC,否则动态库编译出错。 对于CMake,使用cmake CMAKE_CXX_FLGAS="-fPIC" ..
otherwise, error occurs
Linking CXX shared library ../../../../bin/libcommon.so
/usr/bin/ld: /usr/local/lib/libprotobuf.a(common.o): relocation R_X86_64_32S against `.rodata' can not be used when makinga shared object; recompile with -fPIC
/usr/local/lib/libprotobuf.a: error adding symbols: Bad value
By default, make install' will install all the files in /usr/local/bin’, /usr/local/lib' etc. You can specify an installation prefix other than /usr/local’ using --prefix', for instance –prefix=$HOME’.
Static linking is now the default for the Protocol Buffer libraries. Due to issues with Win32’s use of a separate heap for each DLL, as well as binary compatibility issues between different versions of MSVC’s STL library, it is recommended that you use static linkage only. However, it is possible to build libprotobuf and libprotoc as DLLs if you really want. To do this, do the following:
Add an additional flag -Dprotobuf_BUILD_SHARED_LIBS=ON when invoking cmake
Follow the same steps as described in the above section.
When compiling your project, make sure to #define PROTOBUF_USE_DLLS.
[libprotobuf ERROR google/protobuf/descriptor_database.cc:58] File already exists in database: adapter_config.proto [libprotobuf FATAL google/protobuf/descriptor.cc:1315] CHECK failed: generated_database_->Add(encoded_file_descriptor, size): terminate called after throwing an instance of 'google::protobuf::FatalException' what(): CHECK failed: generated_database_->Add(encoded_file_descriptor, size): Aborted (core dumped)
reasons
The problem happens when you have multiple compiled copies of the same .pb.cc file sharing a single copy of libprotobuf.so.
`common`模块编译了`adapter_config.pb.cc`,`node_perception`依赖于`common`,同时也要编译`adapter_config.pb.cc`。运行`node_perception`就会报错。