Mac SOME/IP编译以及Ubuntu的SOME/IP集成与编译

  • vsomeip是BMW实现的开源someip库,目前主要实现了someip的通信和服务发现功能,并在此基础上增加了少许的安全机制。

  • 本文主要从vsomeip的环境搭建,编译,以及对应helloworld程序分析开始,目的在于分析整套vsomeip库的运行机制。

1. Ubuntu编译

1. 代码拉取

vsomeip相关代码可以直接从github上获取。

https://github.com/GENIVI/vsomeip.git

2. 编译

2.1. 安装依赖
  • 由于我的ubuntu版本是20.04,官方文档上的对应boost包的版本过低,因此这里不需要指定对应的boost包版本号
sudo apt-get install libboost-system-dev libboost-thread-dev libboost-log-dev

sudo apt-get install asciidoc source-highlight doxygen graphviz
  • 由于我的ubuntu是20.04版本全新安装的,因此再编译的过程中,遇到了如下的问题:
2.2. 缺少编译环境

-遇到对应图中的问题,主要是对应的编译工具未安装导致的。

CMAKE_C_COMPILER是对应的gcc没有安装

CMAKE_CXX_COMPILER是对应的G++没有安装

CMAKE_MAKE_CONPILER是对应的make命令没有安装
  • 因此执行如下命令安装对应的编译工具
sudo apt-get install gcc g++ make
2.3. 缺少gtest问题
  • 其实缺少gtest应该也不影响大局,但是这里以防万一,加上对应的gtest目录。

  • 根据官方的依赖文档

2.4. 编译vsomeip
mkdir build
cd build
cmake ..
make
  • 根据官方的文档,可以直接运行上述命令进行编译vsomeip库
2.5. 编译helloworld
  • 分析从也是从自带的helloworld程序开始,因此我们先编译对应的helloworld程序。

  • Helloworld程序的编译方法可以查看

  • examples/hello_world/readme

  • 相关的编译命令如下:

cmake --build . --target hello_world
cd ./examples/hello_world/
make

3. 运行

  • 编译完成之后,会在对应的编译目录下生成对应helloworld的二进制程序:hello_world_client和hello_world_service。

  • 这里有个坑需要注意,官方给出的运行命令并不能直接运行。

  • HOST1运行service:

env VSOMEIP_CONFIGURATION=../helloworld-local.json \
VSOMEIP_APPLICATION_NAME=hello_world_service \
./hello_world_service
  • HOST1运行client:
env VSOMEIP_CONFIGURATION=../helloworld-local.json \
VSOMEIP_APPLICATION_NAME=hello_world_client \
./hello_world_client
  • 这里官方文档中,指定的VSOMEIP_CONFIGURATION的配置文件路径在…/下面。但是默认编译完成后,根本没有这个命令。因此,我们需要手动copy一下对应的命令,否则就会出现加载策略文件失败的问题。

  • 将代码目录下的helloworld-local.json 复制到我们的运行目录,因此对应的内容如下。

drwxrwxr-x 3 seven seven 4096 Aug 23 23:16 .
drwxrwxr-x 5 seven seven 4096 Aug 23 02:46 ..
drwxrwxr-x 4 seven seven 4096 Aug 20 00:29 CMakeFiles
-rw-rw-r-- 1 seven seven 1288 Aug 19 23:26 cmake_install.cmake
-rwxrwxr-x 1 seven seven 349512 Aug 22 23:27 hello_world_client
-rw-rw-r-- 1 seven seven 1526 Aug 23 23:16 helloworld-local.json
-rwxrwxr-x 1 seven seven 372872 Aug 23 02:43 hello_world_service
-rw-rw-r-- 1 seven seven 11414 Aug 19 23:27 Makefile
  • 完成之后,修改上述官方指定配置文件的路径,启动程序。

  • 对应修改后的文件如下:

  • HOST1运行service:

env VSOMEIP_CONFIGURATION=./helloworld-local.json \
VSOMEIP_APPLICATION_NAME=hello_world_service \
./hello_world_service
  • HOST1运行client:
env VSOMEIP_CONFIGURATION=./helloworld-local.json \
VSOMEIP_APPLICATION_NAME=hello_world_client \
./hello_world_client
  • 运行成功后service端的运行日志:
2021-07-24 00:39:22.968673 [info] Parsed vsomeip configuration in 0ms
2021-07-24 00:39:22.969368 [info] Using configuration file: "./helloworld-local.json".
2021-07-24 00:39:22.969505 [info] Configuration module loaded.
2021-07-24 00:39:22.969585 [info] Initializing vsomeip application "hello_world_service".
2021-07-24 00:39:22.970287 [info] Instantiating routing manager [Host].
2021-07-24 00:39:22.970967 [info] create_local_server Routing endpoint at /tmp/vsomeip-0
2021-07-24 00:39:22.971693 [info] Application(hello_world_service, 4444) is initialized (11, 100).
2021-07-24 00:39:22.972006 [info] Starting vsomeip application "hello_world_service" (4444) using 2 threads I/O nice 255
2021-07-24 00:39:22.973797 [info] main dispatch thread id from application: 4444 (hello_world_service) is: 7fe67327a700 TID: 30757
2021-07-24 00:39:22.974427 [info] shutdown thread id from application: 4444 (hello_world_service) is: 7fe672a79700 TID: 30758
2021-07-24 00:39:22.975582 [info] Watchdog is disabled!
2021-07-24 00:39:22.976711 [info] OFFER(4444): [1111.2222:0.0] (true)
2021-07-24 00:39:22.976949 [info] io thread id from application: 4444 (hello_world_service) is: 7fe671a77700 TID: 30760
2021-07-24 00:39:22.976941 [info] io thread id from application: 4444 (hello_world_service) is: 7fe673b06740 TID: 30755
2021-07-24 00:39:22.978376 [info] Listening at /tmp/vsomeip-4444
2021-07-24 00:39:22.978504 [info] vSomeIP 3.1.20.3 | (default)
2021-07-24 00:40:30.882696 [info] Application/Client 5555 is registering.
2021-07-24 00:40:30.885026 [info] Client [4444] is connecting to [5555] at /tmp/vsomeip-5555
2021-07-24 00:40:30.888982 [info] REGISTERED_ACK(5555)
2021-07-24 00:40:30.002024 [info] REQUEST(5555): [1111.2222:255.4294967295]
2021-07-24 00:40:30.021586 [info] RELEASE(5555): [1111.2222]
2021-07-24 00:40:30.022233 [info] Application/Client 5555 is deregistering.
2021-07-24 00:40:30.132041 [info] Client [4444] is closing connection to [5555]
2021-07-24 00:40:33.039677 [info] vSomeIP 3.1.20.3 | (default)
2021-07-24 00:40:35.016774 [info] STOP OFFER(4444): [1111.2222:0.0] (true)
2021-07-24 00:40:35.018794 [info] Stopping vsomeip application "hello_world_service" (4444).
  • 运行成功后client端的日志:
2021-07-24 00:40:30.863438 [info] Parsed vsomeip configuration in 0ms
2021-07-24 00:40:30.864396 [info] Using configuration file: "./helloworld-local.json".
2021-07-24 00:40:30.864794 [info] Configuration module loaded.
2021-07-24 00:40:30.865133 [info] Initializing vsomeip application "hello_world_client".
2021-07-24 00:40:30.865472 [info] Instantiating routing manager [Proxy].
2021-07-24 00:40:30.865988 [info] Client [5555] is connecting to [0] at /tmp/vsomeip-0
2021-07-24 00:40:30.866444 [info] Application(hello_world_client, 5555) is initialized (11, 100).
2021-07-24 00:40:30.866878 [info] Starting vsomeip application "hello_world_client" (5555) using 2 threads I/O nice 255
2021-07-24 00:40:30.869134 [info] main dispatch thread id from application: 5555 (hello_world_client) is: 7fd99f664700 TID: 30773
2021-07-24 00:40:30.869406 [info] shutdown thread id from application: 5555 (hello_world_client) is: 7fd99ee63700 TID: 30774
2021-07-24 00:40:30.872267 [info] io thread id from application: 5555 (hello_world_client) is: 7fd99f6ef740 TID: 30772
2021-07-24 00:40:30.873138 [info] io thread id from application: 5555 (hello_world_client) is: 7fd99e662700 TID: 30775
2021-07-24 00:40:30.876012 [info] Listening at /tmp/vsomeip-5555
2021-07-24 00:40:30.876564 [info] Client 5555 (hello_world_client) successfully connected to routing ~> registering..
2021-07-24 00:40:30.887494 [info] Application/Client 5555 (hello_world_client) is registered.
2021-07-24 00:40:30.005002 [info] ON_AVAILABLE(5555): [1111.2222:0.0]
Sending: World
2021-07-24 00:40:30.007028 [info] Client [5555] is connecting to [4444] at /tmp/vsomeip-4444
Received: Hello World
2021-07-24 00:40:30.019968 [info] Stopping vsomeip application "hello_world_client" (5555).
2021-07-24 00:40:30.023966 [info] Application/Client 5555 (hello_world_client) is deregistered.
2021-07-24 00:40:30.025815 [info] Client [5555] is closing connection to [4444]

2. Mac 编译问题。 暂时源码没适配 编译不过去

  • 1、下载开源VSOMEIP代码

  • 2、直接编译

mkdir build
cd build
cmake ..
make
  • 3、第一坑,没有boost,装boost即可,参考如下方法

    https://blog.csdn.net/qq_41350775/article/details/107066438

4、再次cmake …/

  • 报如下错误
<command line>:4:9: error: macro name must be an identifier
#define -DBOOST_LOG_DYN_LINK 1
打开CMakeLists.txt,添加如下一个配置

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    set(OS "Darwin")
    set(DL_LIBRARY "dl")
    set(EXPORTSYMBOLS "-Wl,-export-dynamic -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap.gcc")
    set(NO_DEPRECATED "")
    set(OPTIMIZE "")
    set(OS_CXX_FLAGS "-D_GLIBCXX_USE_NANOSLEEP -pthread -O -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector -fasynchronous-unwind-tables -fno-omit-frame-pointer -D_FORTIFY_SOURCE=2")
endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
其实这是把linux的配置抄了一下,至少目前的错误可以过了,但是是否设置正确,得往后走的看了。

5、报错

vsomeip/implementation/endpoints/src/credentials.cpp:19:37: error: use of undeclared identifier 'SO_PASSCRED'
  • 目前识别到的是vsomeip没有对mac做适配,如果想继续编译的话,可能需要修改源码了。
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Army_Ma

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值