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

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.lqws.cn/news/194221.html

相关文章:

  • 使用python把json数据追加进文件,然后每次读取时,读取第一行并删除
  • MySQL的优化部分介绍
  • MySQL体系架构解析(三):MySQL数据存储的揭秘
  • 第四讲:类和对象(下)
  • mamba架构和transformer区别
  • 导出pcap文件中的特定数据包
  • STM32外设问题总结
  • 六级作文--句型
  • Abaqus模拟弯曲问题之剪力自锁与沙漏化现象
  • 学习日记-day23-6.6
  • [蓝桥杯]轨道炮
  • Python 构建法律DeepSeek RAG
  • Dubbo学习(一):Dubbo介绍
  • 装载机防撞系统:智能守护,筑牢作业现场人员安全防线
  • win11部署suna
  • 三、元器件的选型
  • python闭包与装饰器
  • 【大厂机试题解法笔记】区间交集
  • Linux文件系统详解:从入门到精通
  • 编译原理笔记
  • ComfyUI 文生图教程,进行第一次的图片生成
  • curl获取ip定位信息 --- libcurl-multi(三)
  • RocketMQ入门5.3.2版本(基于java、SpringBoot操作)
  • c++算法学习5——贪心算法
  • 类Transformer架构
  • 在线OJ项目测试
  • JMM初学
  • 51单片机——计分器
  • 【Go面试陷阱】对未初始化的chan进行读写为何会卡死?
  • 【汇编逆向系列】八、函数调用包含混合参数-8种参数传参,条件跳转指令,转型指令,movaps 16字节指令