1 fdbus编译运行

系统

Ubuntu 18.04.5 LTS 64bit

编译

#下载编译fdbus

cd ~/workspace

git clone git@github.com:jfq3301/fdbus.git

#我想在代码中做些修改,所以克隆的自己仓库。原始仓库是:git clone https://github.com/jeremyczhen/fdbus.git #get fdbus source code

cd fdbus

mkdir -p build/install

cd build #create directory for out-of-source build

cmake -DCMAKE_INSTALL_PREFIX=install ../cmake

make install

编译成功结果如下:

Scanning dependencies of target fdbus-clib

[ 95%] Building CXX object CMakeFiles/fdbus-clib.dir/home/jfq/1_work/12_git/fdbus/c/fdbus_clib.cpp.o

[ 97%] Building CXX object CMakeFiles/fdbus-clib.dir/home/jfq/1_work/12_git/fdbus/c/fdbus_client.cpp.o

[ 98%] Building CXX object CMakeFiles/fdbus-clib.dir/home/jfq/1_work/12_git/fdbus/c/fdbus_server.cpp.o

[100%] Linking CXX shared library libfdbus-clib.so

[100%] Built target fdbus-clib

 

#打开printf log输出

在fdbus/cmake/CMakeLists.txt修改如下选项为ON:

option(fdbus_LOG_TO_STDOUT "Log to stdout" ON)

在fdbus/server/main_ns.cpp增加头文件#include <utils/Log.h>,

在main函数中增加:LOG_D("[%s][%d]Enter.\n", __FUNCTION__, __LINE__);

再次make,结果如下:

~/1_work/12_git/fdbus/build$ ./name_server

[main][100]Enter.

 

编译protobuffer

sudo apt-get install autoconf automake libtool curl make g++ unzip

git clone https://github.com/protocolbuffers/protobuf.git

cd protobuf

git submodule update --init --recursive

./autogen.sh

./configure

make

make check

sudo make install

sudo ldconfig # refresh shared library cache.

 

make check结果如下

============================================================================

Testsuite summary for Protocol Buffers 3.9.0-rc-1

============================================================================

# TOTAL: 7

# PASS:  7

# SKIP:  0

# XFAIL: 0

# FAIL:  0

# XPASS: 0

# ERROR: 0

============================================================================

 

#编译example

##编译proto文件

protoc proto文件路径 --cpp_out=C++代码文件导出目录

cd ./fdbus/example/idl

protoc ./common.base.Example.proto --cpp_out=./idl-gen

##修改Makefile

在./fdbus/cmake/CMakeLists.txt中添加include(example.cmake),修改./fdbus/cmake/example.cmake,主要是变更路径:

link_directories(${PACKAGE_SOURCE_ROOT}/../protobuf/src/.libs)

add_executable(fdbclienttest

    ${PACKAGE_SOURCE_ROOT}/example/client-server/fdb_test_client.cpp

   ${PACKAGE_SOURCE_ROOT}/example/idl-gen/common.base.Example.pb.cc

)

target_link_libraries(fdbclienttest protobuf-lite protobuf)

编译时出现如下错误,需要添加link_directories(${PACKAGE_SOURCE_ROOT}/../protobuf/src/.libs)用于指定最新编译的protobuf路径。

fdbus/example/client-server/fdb_test_server.cpp.o:在函数‘google::protobuf::internal::GetEmptyStringAlreadyInited[abi:cxx11]()’中:

fdb_test_server.cpp:(.text._ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedB5cxx11Ev[_ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedB5cxx11Ev]+0x7):对‘google::protobuf::internal::fixed_address_empty_string[abi:cxx11]’未定义的引用

 

上一篇:从通过grep统计protobuf 字节数看C++字符串


下一篇:Protobuf入门