当前位置: 首页 > 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/

相关文章:

  • curl获取ip定位信息 --- system(一)
  • Lombok 的 @Data 注解失效,未生成 getter/setter 方法引发的HTTP 406 错误
  • 基于 BGE 模型与 Flask 的智能问答系统开发实践
  • 大模型与 NLP、Transformer 架构
  • 动力电池点焊机:驱动电池焊接高效与可靠的核心力量|比斯特自动化
  • 深入理解Java中的this关键字:核心概念与实践应用
  • XXTEA,XTEA与TEA
  • html+css+js趣味小游戏~Cookie Clicker放置休闲(附源码)
  • 探索 Java 垃圾收集:对象存活判定、回收流程与内存策略
  • 【大厂机试题多种解法笔记】小明减肥
  • 【推荐算法】DeepFM:特征交叉建模的革命性架构
  • python报错No module named ‘tensorflow.keras‘
  • 【CF】Day77——Codeforces Round 877 (Div. 2) BCD (构造场)
  • 智绅科技 —— 智慧养老 + 数字健康,构筑银发时代安全防护网
  • TDengine 替换 Hadoop,彻底解决数据丢失问题 !
  • 【p2p、分布式,区块链笔记 MESH】Bluetooth蓝牙通信 BLE Mesh协议的拓扑结构 定向转发机制
  • Redis哨兵模式
  • 【SSM】MyBatisPlus笔记:快速上手MyBatisPlus
  • CVE-2020-17519源码分析与漏洞复现(Flink 任意文件读取)
  • 沙市区举办资本市场赋能培训会 点赋科技分享智能消费新实践
  • 免费做司考真题的网站/抖音广告
  • 仿制手机网站教程/推手平台哪个靠谱
  • php网站留言板漏洞/专业关键词排名优化软件
  • 十款看免费行情的软件推荐/seo优化网络
  • ai做网站 如何切图/黄页网站推广公司
  • 手机网站模板安装方法/seo外链推广员