Linux C++ Commonapi环境搭建

32 篇文章 3 订阅

参考了以下文章:
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

  • 8
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要在Linux上搭建VSCode的C++开发环境,您需要按照以下步骤进行配置: 1. 首先,确保您已经安装了Visual Studio Code。您可以从官方网站下载并安装它。 2. 打开VSCode并点击左侧的Extensions图标(或使用快捷键Ctrl+Shift+X)。 3. 在搜索框中输入"C/C++",然后点击安装C/C++扩展。 4. 安装完成后,您可以开始配置编译器。在VSCode中,点击左侧的文件夹图标,打开您的C++项目文件夹。 5. 在项目文件夹中创建一个新的C++源文件,例如"helloworld.cpp"。 6. 在"helloworld.cpp"文件中,粘贴以下代码并保存: ```cpp #include <iostream> #include <vector> #include <string> using namespace std; int main() { vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"}; for (const string& word : msg) { cout << word << " "; } cout << endl; } ``` 7. 现在,您可以使用VSCode的编译和调试功能来运行这个简单的C++程序了。 请注意,VSCode本身只是一个文本编辑器,您需要通过配置来使用GCC C++编译器(g++)和GDB调试器。\[2\]确保您已经正确安装了这些工具,并按照上述步骤进行配置,以便在VSCode中进行C++开发。 #### 引用[.reference_title] - *1* [【LinuxC++开发】第三篇·使用VSCode进行C++开发](https://blog.csdn.net/qq_52785580/article/details/123153043)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [基于Linux下的vscode c/c++开发环境搭建详细教程](https://blog.csdn.net/icacxygh001/article/details/120981354)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值