Linux C++ Commonapi环境搭建

荀辰钊
2023-12-01

参考了以下文章:
https://github.com/lixiaolia/commonapi_someip_demo
https://blog.csdn.net/u010743397/article/details/107892463
提前说明,整个安装过程需要下载和安装一些程序,总耗时较长。
我的安装环境是ubuntu20.04

安装依赖:
sudo apt-get install cmake cmake-qt-gui libexpat-dev expat default-jre

编译和安装 boost:(可以去网上下载最新的版本)
https://www.boost.org/users/download/
例如:
cd boost_1_57_0
./bootstrap.sh
./b2 link=shared
sudo ./b2 install

编译和安装 vsomeip:
创建一个目录作为工作目录,以下行为都在工作目录下操作
git clone https://github.com/GENIVI/vsomeip.git
cd vsomeip
mkdir build
cd build
cmake -DENABLE_SIGNAL_HANDLING=1 -DDIAGNOSIS_ADDRESS=0x10 …

关于选项有以下说明,直接贴原文:
With ENABLE_SIGNAL_HANDLING=1 the signal handling of vsomeip (SIGINT/SIGTERM) is enabled; that you can abort vsomeip applications by ctrl-c. 第一个选项表示vsomeip接收SIGINT/SIGTERM信号,用ctro+c可以成功退出程序。
The second parameter DIAGNOSIS_ADDRESS specifies the first byte of the SOME/IP client ID (don’t care if you do not know at the moment what it is). You just have to know that the client ID is a number in the SOME/IP message header which has to be unique in the system. In order to make sure that it is unique, for each device (or node) the vsomeip implementation sets the first byte of this client ID to a fixed value which must be different for all devices in the SOME/IP network. If you only intend to communicate locally via SOME/IP this is not necessary.
第二个参数是用来指定some/ip client id的第一个字节,如果在网络上多机通信,有必要区分不同的client,这个时候这个参数很有用。

第一次编译:
– Checking for module ‘automotive-dlt >= 2.11’
– No package ‘automotive-dlt’ found
– Checking for module ‘libsystemd’
– No package ‘libsystemd’ found
– Systemd was not found, watchdog disabled!
– Default configuration folder: /etc/vsomeip
– Default configuration file: /etc/vsomeip.json
Predefined base path: /tmp
Predefined unicast address: 127.0.0.1
Predefined diagnosis address: 0x10
– Found Doxygen: /usr/bin/doxygen (found version “1.8.17”) found components: doxygen dot
dot found
CMake Warning at CMakeLists.txt:564 (message):
asciidoc is not installed. Readme can not be built.

– GTEST_ROOT is not defined. For building the tests the variable
GTEST_ROOT has to be defined. Tests can not be built.
– Configuring done
– Generating done
按照提示缺少的库,我安装了libclang-9,它可以解决doxygen 找不到的问题,也可以sudo apt install doxygen
$sudo apt install libclang1-9

然后重新运行cmake -DENABLE_SIGNAL_HANDLING=1 -DDIAGNOSIS_ADDRESS=0x10 …
第二次编译:

  • Using boost version: 107100
    – Checking for module ‘automotive-dlt >= 2.11’
    – No package ‘automotive-dlt’ found
    – Checking for module ‘libsystemd’
    – No package ‘libsystemd’ found
    – Systemd was not found, watchdog disabled!
    – Default configuration folder: /etc/vsomeip
    – Default configuration file: /etc/vsomeip.json
    Predefined base path: /tmp
    Predefined unicast address: 127.0.0.1
    Predefined diagnosis address: 0x10
    dot found
    CMake Warning at CMakeLists.txt:564 (message):
    asciidoc is not installed. Readme can not be built.

– GTEST_ROOT is not defined. For building the tests the variable
GTEST_ROOT has to be defined. Tests can not be built.
– Configuring done
– Generating done
按照提示,运行$sudo apt install libsystemd-dev
然后重新运行cmake -DENABLE_SIGNAL_HANDLING=1 -DDIAGNOSIS_ADDRESS=0x10 …
第三次编译:
– Using boost version: 107100
– Checking for module ‘automotive-dlt >= 2.11’
– No package ‘automotive-dlt’ found
– Checking for module ‘libsystemd’
– Found libsystemd, version 245
– Default configuration folder: /etc/vsomeip
– Default configuration file: /etc/vsomeip.json
Predefined base path: /tmp
Predefined unicast address: 127.0.0.1
Predefined diagnosis address: 0x10
dot found
CMake Warning at CMakeLists.txt:564 (message):
asciidoc is not installed. Readme can not be built.

– GTEST_ROOT is not defined. For building the tests the variable
GTEST_ROOT has to be defined. Tests can not be built.
– Configuring done
– Generating done

目前还缺少automotive-dlt库。到网址https://github.com/GENIVI/dlt-daemon,按照说明安装dlt-daemon。安装时其中cmake 的命令改为
$cmake WITH_DLT_PKGCONFIG=ON …
然后需要继续执行make, sudo make install, sudo ldconfig.
这样就安装了automotive-dlt

回到vsomeip/build目录下,继续执行$cmake -DENABLE_SIGNAL_HANDLING=1 -DDIAGNOSIS_ADDRESS=0x10 …
第四次编译:
– Using boost version: 107100
– Checking for module ‘automotive-dlt >= 2.11’
– Found automotive-dlt , version 2.18.7
– Default configuration folder: /etc/vsomeip
– Default configuration file: /etc/vsomeip.json
Predefined base path: /tmp
Predefined unicast address: 127.0.0.1
Predefined diagnosis address: 0x10
dot found
CMake Warning at CMakeLists.txt:564 (message):
asciidoc is not installed. Readme can not be built.

– GTEST_ROOT is not defined. For building the tests the variable
GTEST_ROOT has to be defined. Tests can not be built.
– Configuring done
– Generating done
可以看出缺少asciidoc
然后安装asciidoc, 执行 s u d o a p t i n s t a l l a s c i i d o c 然 后 继 续 执 行 sudo apt install asciidoc 然后继续执行 sudoaptinstallasciidoccmake -DENABLE_SIGNAL_HANDLING=1 -DDIAGNOSIS_ADDRESS=0x10 …
第五次编译:
– Using boost version: 107100
– Default configuration folder: /etc/vsomeip
– Default configuration file: /etc/vsomeip.json
Predefined base path: /tmp
Predefined unicast address: 127.0.0.1
Predefined diagnosis address: 0x10
dot found
CMake Warning at CMakeLists.txt:566 (message):
source-highlight is not installed. Readme can not be built.

– GTEST_ROOT is not defined. For building the tests the variable
GTEST_ROOT has to be defined. Tests can not be built.
– Configuring done
– Generating done
可以看出缺少source-hightlight, 执行 s u d o a p t i n s t a l l s o u r c e − h i g h l i g h t 然 后 继 续 执 行 sudo apt install source-highlight 然后继续执行 sudoaptinstallsourcehighlightcmake -DENABLE_SIGNAL_HANDLING=1 -DDIAGNOSIS_ADDRESS=0x10 …
第六次编译:
– Using boost version: 107100
– Default configuration folder: /etc/vsomeip
– Default configuration file: /etc/vsomeip.json
Predefined base path: /tmp
Predefined unicast address: 127.0.0.1
Predefined diagnosis address: 0x10
dot found
asciidoc found
source-highlight found
– GTEST_ROOT is not defined. For building the tests the variable
GTEST_ROOT has to be defined. Tests can not be built.
– Configuring done
– Generating done
可以看出GTEST_ROOT 未设置,需要安装googletest. $sudo apt install googletest
$cmake -DGTEST_ROOT=/usr/src/googletest -DENABLE_SIGNAL_HANDLING=1 -DDIAGNOSIS_ADDRESS=0x10 …

make
sudo make install
注意,这里生成的vsomeip库后面有个3,引用的时候需要加上,或者自己在库路径下创建不带3的软连接

编译和安装 CommonAPI Core Runtime:
git clone https://github.com/GENIVI/capicxx-core-runtime.git
cd capicxx-core-runtime/
mkdir build
cd build
cmake …
make
sudo make install

编译和安装 CommonAPI SomeIP Runtime:
git clone https://github.com/GENIVI/capicxx-someip-runtime.git
cd capicxx-someip-runtime/
mkdir build
cd build
cmake -DUSE_INSTALLED_COMMONAPI=OFF …
make
sudo make install

切换JAVA版本到Oracle jdk1.8:(已经是1.8的可忽略,非openJDK0),这里需要自己下载并设置。
安装java方法请上网搜索
java -version # 检查是否配置成功

编译CommonAPI Core Runtime代码生成工具:
git clone https://github.com/GENIVI/capicxx-core-tools.git
cd capicxx-core-tools/org.genivi.commonapi.core.releng
mvn -Dtarget.id=org.genivi.commonapi.core.target clean verify
(命令执行时间很长)
(报错,将mvn版本升级到3.8.2)

执行成功后,会在capicxx-core-tools/org.genivi.commonapi.core.cli.product/target/products/或者capicxx-core-tools-master/org.genivi.commonapi.core.cli.product/target/products/目录下,生成压缩文件commonapi_core_generator.zip
解压得到代码生成工具:(commonapi_core_generator,用来解析fidl文件)

在工作目录新建someip_dev文件夹
cd someip_dev
unzip -d ./commonapi_core_generator …/capicxx-core-tools/org.genivi.commonapi.core.cli.product/target/products/commonapi_core_generator.zip(根据自己实际修改)
unzip -d ./commonapi_core_generator …/capicxx-core-tools-master/org.genivi.commonapi.core.cli.product/target/products/commonapi_core_generator.zip
chmod +x ./commonapi_core_generator/commonapi-core-generator-linux-x86_64

编译CommonAPI SomeIP Runtime代码生成工具:
git clone https://github.com/GENIVI/capicxx-someip-tools.git
cd capicxx-someip-tools/org.genivi.commonapi.someip.releng/
mvn -DCOREPATH=/home/lxl/Develop/capicxx-core-tools -Dtarget.id=org.genivi.commonapi.someip.target clean verify 根据自己实际修改,例如
mvn -DCOREPATH=…/…/capicxx-core-tools-master -Dtarget.id=org.genivi.commonapi.someip.target clean verify

执行成功后,会在capicxx-someip-tools/org.genivi.commonapi.someip.cli.product/target/products/或者capicxx-someip-tools-master/org.genivi.commonapi.someip.cli.product/target/products/下生成压缩文件commonapi_someip_generator.zip,用来解析fdepl文件
解压得到代码生成工具:

org.genivi.commonapi.someip.cli.product/target/products/commonapi_someip_generator.zip
cd someip_dev
unzip -d ./commonapi_someip_generator ./capicxx-someip-tools/org.genivi.commonapi.someip.cli.product/target/products/commonapi_someip_generator.zip 根据自己实际修改
unzip -d ./commonapi_someip_generator …/capicxx-someip-tools/org.genivi.commonapi.someip.cli.product/target/products/commonapi_someip_generator.zip
chmod +x ./commonapi_someip_generator/commonapi-someip-generator-linux-x86_64

至此,环境已经安装完成,下面运行测试程序。

到工程capicxx-core-tools/CommonAPI-Examples/E01HelloWorld目录下,
自带的CMakeLists.txt编译报错,重新修改为:

cmake_minimum_required(VERSION 2.8)
project(E01HelloWorld)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++0x")
include_directories(
    src-gen
    src
    /usr/local/include/CommonAPI-3.2
    /usr/local/include/vsomeip
)
link_directories(
    /usr/local/lib
)
add_executable(E01HelloWorldClient
        src/E01HelloWorldClient.cpp
        src-gen/v0/commonapi/examples/E01HelloWorldSomeIPProxy.cpp
        src-gen/v0/commonapi/examples/E01HelloWorldSomeIPDeployment.cpp
)

target_link_libraries(E01HelloWorldClient CommonAPI CommonAPI-SomeIP vsomeip3)
add_executable(E01HelloWorldService
        src/E01HelloWorldService.cpp
        src/E01HelloWorldStubImpl.cpp
        src-gen/v0/commonapi/examples/E01HelloWorldSomeIPStubAdapter.cpp
        src-gen/v0/commonapi/examples/E01HelloWorldSomeIPDeployment.cpp
)

target_link_libraries(E01HelloWorldService CommonAPI CommonAPI-SomeIP vsomeip3)

add_library(E01HelloWorldShared SHARED  
	src/pythonWrapper.cpp
        src/E01HelloWorldStubImpl.cpp
        src-gen/v0/commonapi/examples/E01HelloWorldSomeIPStubAdapter.cpp
        src-gen/v0/commonapi/examples/E01HelloWorldSomeIPDeployment.cpp
)

target_link_libraries(E01HelloWorldShared CommonAPI CommonAPI-SomeIP vsomeip3)

工程源码在src下,
在工程目录fidl下,会有E01HelloWorld.fidl和E01HelloWorld-SomeIP.fdepl

创建目录cgen,将上面解压出来的commonapi_someip_generator 和 commonapi_core_generator文件夹复制到cgen下。

然后执行
./cgen/commonapi_core_generator/commonapi-core-generator-linux-x86_64 -sk -pf ./fidl/E01HelloWorld.fidl
./cgen/commonapi_someip_generator/commonapi-someip-generator-linux-x86_64 -ll verbose ./fidl/E01HelloWorld-SomeIP.fdepl

然后创建目录build
mkdir build
cd build
cmake …
make
如果编译出错,运行sudo ldconfig可能会解决
成功后会生成E01HelloWorldClient和E01HelloWorldService文件,
分别在不同的终端运行这两个文件,可以看到通信消息。
注意:设置变量值与执行程序的语句要放在同一行,最前面可以加env也可以不加。
env VSOMEIP_CONFIGURATION=…/vsomeip-local.json VSOMEIP_APPLICATION_NAME=service-sample ./E01HelloWorldService

env VSOMEIP_CONFIGURATION=…/vsomeip-local.json VSOMEIP_APPLICATION_NAME=client-sample ./E01HelloWorldClient

 类似资料: