当前位置: 首页 > ai >正文

Ubuntu系统下交叉编译cJSON

一、参考资料

二、准备工作

1. 编译环境

  • 宿主机:Ubuntu 20.04.6 LTS
  • Host:ARM32位
  • 交叉编译器:arm-linux-gnueabihf-gcc-11.1.0

2. 设置交叉编译工具链

在交叉编译之前,需要设置交叉编译工具链的环境变量。

export PATH=/path/to/toolchains/arm-linux-gnueabihf/bin:$PATH

三、交叉编译cJSON

1. 下载源码

GitHub - DaveGamble/cJSON: Ultralightweight JSON parser in ANSI C

下载并解压源码。

tar -xvzf cJSON-1.7.18.tar.gz

2. 编译安装

cd cJSON-1.7.18
mkdir build && cd buildcmake -DCMAKE_INSTALL_PREFIX=/path/to/cjson/arm_install \-DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc \-DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ \-DBUILD_SHARED_LIBS=ON \-DENABLE_CJSON_TEST=OFF ..  # 关闭测试程序make -j8
make install 

编译安装之后的文件目录:

yoyo@yoyo:~/360Downloads/cJSON-1.7.18$ tree -L 3 arm_install/
arm_install/
├── include
│   └── cjson
│       └── cJSON.h
└── lib├── cmake│   └── cJSON├── libcjson.so -> libcjson.so.1├── libcjson.so.1 -> libcjson.so.1.7.18├── libcjson.so.1.7.18└── pkgconfig└── libcjson.pc

cmake编译:

yoyo@yoyo:~/360Downloads/cJSON-1.7.18/build$ cmake -DCMAKE_INSTALL_PREFIX=/path/to/cJSON-1.7.18/arm_install \
>   -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc \
>       -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ \
>       -DBUILD_SHARED_LIBS=ON \
>       -DENABLE_CJSON_TEST=OFF ..
CMake Deprecation Warning at CMakeLists.txt:2 (cmake_minimum_required):Compatibility with CMake < 3.10 will be removed from a future version ofCMake.Update the VERSION argument <min> value.  Or, use the <min>...<max> syntaxto tell CMake that the project requires at least <min> but has been updatedto work with policies introduced by <max> or earlier.-- The C compiler identification is GNU 11.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /path/to/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Performing Test FLAG_SUPPORTED_stdc89
-- Performing Test FLAG_SUPPORTED_stdc89 - Success
-- Performing Test FLAG_SUPPORTED_pedantic
-- Performing Test FLAG_SUPPORTED_pedantic - Success
-- Performing Test FLAG_SUPPORTED_Wall
-- Performing Test FLAG_SUPPORTED_Wall - Success
-- Performing Test FLAG_SUPPORTED_Wextra
-- Performing Test FLAG_SUPPORTED_Wextra - Success
-- Performing Test FLAG_SUPPORTED_Werror
-- Performing Test FLAG_SUPPORTED_Werror - Success
-- Performing Test FLAG_SUPPORTED_Wstrictprototypes
-- Performing Test FLAG_SUPPORTED_Wstrictprototypes - Success
-- Performing Test FLAG_SUPPORTED_Wwritestrings
-- Performing Test FLAG_SUPPORTED_Wwritestrings - Success
-- Performing Test FLAG_SUPPORTED_Wshadow
-- Performing Test FLAG_SUPPORTED_Wshadow - Success
-- Performing Test FLAG_SUPPORTED_Winitself
-- Performing Test FLAG_SUPPORTED_Winitself - Success
-- Performing Test FLAG_SUPPORTED_Wcastalign
-- Performing Test FLAG_SUPPORTED_Wcastalign - Success
-- Performing Test FLAG_SUPPORTED_Wformat2
-- Performing Test FLAG_SUPPORTED_Wformat2 - Success
-- Performing Test FLAG_SUPPORTED_Wmissingprototypes
-- Performing Test FLAG_SUPPORTED_Wmissingprototypes - Success
-- Performing Test FLAG_SUPPORTED_Wstrictoverflow2
-- Performing Test FLAG_SUPPORTED_Wstrictoverflow2 - Success
-- Performing Test FLAG_SUPPORTED_Wcastqual
-- Performing Test FLAG_SUPPORTED_Wcastqual - Success
-- Performing Test FLAG_SUPPORTED_Wundef
-- Performing Test FLAG_SUPPORTED_Wundef - Success
-- Performing Test FLAG_SUPPORTED_Wswitchdefault
-- Performing Test FLAG_SUPPORTED_Wswitchdefault - Success
-- Performing Test FLAG_SUPPORTED_Wconversion
-- Performing Test FLAG_SUPPORTED_Wconversion - Success
-- Performing Test FLAG_SUPPORTED_Wccompat
-- Performing Test FLAG_SUPPORTED_Wccompat - Success
-- Performing Test FLAG_SUPPORTED_fstackprotectorstrong
-- Performing Test FLAG_SUPPORTED_fstackprotectorstrong - Success
-- Performing Test FLAG_SUPPORTED_Wcomma
-- Performing Test FLAG_SUPPORTED_Wcomma - Failed
-- Performing Test FLAG_SUPPORTED_Wdoublepromotion
-- Performing Test FLAG_SUPPORTED_Wdoublepromotion - Success
-- Performing Test FLAG_SUPPORTED_Wparentheses
-- Performing Test FLAG_SUPPORTED_Wparentheses - Success
-- Performing Test FLAG_SUPPORTED_Wformatoverflow
-- Performing Test FLAG_SUPPORTED_Wformatoverflow - Success
-- Performing Test FLAG_SUPPORTED_Wunusedmacros
-- Performing Test FLAG_SUPPORTED_Wunusedmacros - Success
-- Performing Test FLAG_SUPPORTED_Wmissingvariabledeclarations
-- Performing Test FLAG_SUPPORTED_Wmissingvariabledeclarations - Failed
-- Performing Test FLAG_SUPPORTED_Wusedbutmarkedunused
-- Performing Test FLAG_SUPPORTED_Wusedbutmarkedunused - Failed
-- Performing Test FLAG_SUPPORTED_Wswitchenum
-- Performing Test FLAG_SUPPORTED_Wswitchenum - Success
-- Performing Test FLAG_SUPPORTED_fvisibilityhidden
-- Performing Test FLAG_SUPPORTED_fvisibilityhidden - Success
-- Configuring done (1.5s)
-- Generating done (0.0s)
CMake Warning:Manually-specified variables were not used by the project:CMAKE_CXX_COMPILER-- Build files have been written to: /path/to/cJSON-1.7.18/build

make编译:

yoyo@yoyo:~/360Downloads/cJSON-1.7.18/build$ make -j8
[ 50%] Building C object CMakeFiles/cjson.dir/cJSON.c.o
[100%] Linking C shared library libcjson.so
[100%] Built target cjson

make install 安装:

yoyo@yoyo:~/360Downloads/cJSON-1.7.18/build$ make install 
[100%] Built target cjson
Install the project...
-- Install configuration: ""
-- Installing: /path/to/cJSON-1.7.18/arm_install/include/cjson/cJSON.h
-- Installing: /path/to/cJSON-1.7.18/arm_install/lib/pkgconfig/libcjson.pc
-- Installing: /path/to/cJSON-1.7.18/arm_install/lib/libcjson.so.1.7.18
-- Installing: /path/to/cJSON-1.7.18/arm_install/lib/libcjson.so.1
-- Installing: /path/to/cJSON-1.7.18/arm_install/lib/libcjson.so
-- Installing: /path/to/cJSON-1.7.18/arm_install/lib/cmake/cJSON/cjson.cmake
-- Installing: /path/to/cJSON-1.7.18/arm_install/lib/cmake/cJSON/cjson-noconfig.cmake
-- Installing: /path/to/cJSON-1.7.18/arm_install/lib/cmake/cJSON/cJSONConfig.cmake
-- Installing: /path/to/cJSON-1.7.18/arm_install/lib/cmake/cJSON/cJSONConfigVersion.cmake

3. 移植到开发板

cp -arf /path/to/cJSON/arm_install/lib/ /usr/cJSON/
http://www.xdnf.cn/news/12257.html

相关文章:

  • IDEA运行Tomcat出现乱码问题解决汇总
  • 三种读写传统xls格式文件开源库libxls、xlslib、BasicExcel的比较
  • c++ chrono头文件含义
  • Ubuntu系统配置C++的boost库(含filesystem模块)的方法
  • 前缀和题目:逐步求和得到正数的最小值
  • Vue事件总线
  • MyBatis 查询功能实现全流程
  • 《操盘实战》速读笔记
  • 使用Hutool工具进行rsa加密解密示例:
  • Linux进程替换以及exec六大函数运用
  • 【电赛培训课】测量与信号类赛题分析
  • Power Apps:自动发送运行错误邮件
  • 图着色问题(回溯)
  • Redux:不可变数据与纯函数的艺术
  • Windows和Ubuntu双系统,删除Windows
  • 用WPDRRC模型,构建企业安全防线
  • 使用Java实现M3U8视频文件合并的完整指南
  • openGauss数据库备份与恢复实践
  • 口语考试准备part1(西电)
  • Python制作史莱姆桌面宠物!可爱的
  • Apollo Auto:Cyber RT 与 ROS 通信
  • 攻防世界RE-happyctf
  • 对话式AI文本转语音合成软件CSM整合包,Sesame AI Labs多人文字转语音工具
  • CUDA安装与多版本管理
  • 算法训练第九天
  • 无法下载CUDA,下载界面链接打开异常
  • 永磁同步电机无感观测器与在线参数识别分别是什么,区别与联系是什么
  • [科研理论]机器人路径规划算法总结及fast_planner经典算法解读
  • Python6.5打卡(day37)
  • HSL颜色控制及使用示例(Hue-Saturation-Lightness)