openwrt之libjson-c

本文深入探讨了json-c库,一个用于处理javascript对象表示的高效库。它提供了多种功能,包括JSON数据的读取、写入、解析和生成。作为C语言编写的库,json-c旨在提供简洁且高效的JSON操作接口,适用于各种C语言应用。本文将介绍其主要特性、使用方法及如何集成到现有项目中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#
# Copyright (C) 2006-2012 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/version.mk

PKG_NAME:=json-c
PKG_REV:=8ba19375d53347d08b82efef609ff352eefa9093
PKG_VERSION:=0.12
PKG_RELEASE:=2

PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=$(PKG_REV)
PKG_SOURCE_SUBDIR:=json-c-$(PKG_VERSION)
PKG_SOURCE:=$(PKG_SOURCE_SUBDIR).tar.gz
PKG_SOURCE_URL:=https://github.com/json-c/json-c.git
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_FIXUP:=autoreconf

PKG_LICENSE:=MIT
PKG_LICENSE_FILES:=COPYING

TARGET_CFLAGS += $(FPIC)

PKG_BUILD_PARALLEL:=1
HOST_BUILD_PARALLEL:=1
PKG_INSTALL:=1

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/host-build.mk

define Package/json-c/description
    This package contains a library for javascript object notation backends.
endef

define Package/json-c
  SECTION:=libs
  CATEGORY:=Libraries
  TITLE:=json-c-0.12
  MAINTAINER:=
  URL:= https://github.com/json-c/json-c/wiki
endef

define Build/InstallDev
    $(INSTALL_DIR) $(1)/usr/include
    $(CP) $(PKG_INSTALL_DIR)/usr/include/json-c $(1)/usr/include/
    $(INSTALL_DIR) $(1)/usr/lib
    $(CP) $(PKG_INSTALL_DIR)/usr/lib/libjson-c.{a,so*} $(1)/usr/lib/
    $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
    $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/json-c.pc $(1)/usr/lib/pkgconfig/
endef

define Package/json-c/install
    $(INSTALL_DIR) $(1)/usr/lib
    $(CP) $(PKG_INSTALL_DIR)/usr/lib/libjson-c.so.* $(1)/usr/lib/
endef

$(eval $(call BuildPackage,json-c))
make[1]: Entering directory '/openwrt/openwrt-15.05.1' make[2]: Entering directory '/openwrt/openwrt-15.05.1/package/helloworld/helloworld' rm -f /openwrt/openwrt-15.05.1/bin/ar71xx/packages/base/helloworld_* rm -f /openwrt/openwrt-15.05.1/staging_dir/target-mips_34kc_uClibc-0.9.33.2/stamp/._installed rm -f /openwrt/openwrt-15.05.1/staging_dir/target-mips_34kc_uClibc-0.9.33.2/packages/.list /openwrt/openwrt-15.05.1/staging_dir/host/packages/.list rm -rf /openwrt/openwrt-15.05.1/build_dir/target-mips_34kc_uClibc-0.9.33.2/helloworld-1.0 make[2]: Leaving directory '/openwrt/openwrt-15.05.1/package/helloworld/helloworld' make[1]: Leaving directory '/openwrt/openwrt-15.05.1' make[1]: Entering directory '/openwrt/openwrt-15.05.1' make[2]: Entering directory '/openwrt/openwrt-15.05.1/package/libs/toolchain' mkdir -p /openwrt/openwrt-15.05.1/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain touch /openwrt/openwrt-15.05.1/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/.prepared_0c0f7031f78967ca687e5628984dfab9 rm -f /openwrt/openwrt-15.05.1/staging_dir/target-mips_34kc_uClibc-0.9.33.2/stamp/.toolchain_installed (cd /openwrt/openwrt-15.05.1/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/./; if [ -x ./configure ]; then find /openwrt/openwrt-15.05.1/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/ -name config.guess | xargs -r chmod u+w; find /openwrt/openwrt-15.05.1/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/ -name config.guess | xargs -r -n1 cp --remove-destination /openwrt/openwrt-15.05.1/scripts/config.guess; find /openwrt/openwrt-15.05.1/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/ -name config.sub | xargs -r chmod u+w; find /openwrt/openwrt-15.05.1/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/ -name config.sub | xargs -r -n1 cp --remove-destination /openwrt/openwrt-15.05.1/scripts/config.sub; AR="mips-openwrt-linux-uclibc-gcc-ar" AS="mips-openwrt-linux-uclibc-gcc -c -Os -pipe -mno-branch-likely -mips32r2 -mtune=34kc -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float" LD=mips-openwrt-linux-uclibc-ld NM="mips-openwrt-linux-uclibc-gcc-nm" CC="mips-openwrt-linux-uclibc-gcc" GCC="mips-openwrt-linux-uclibc-gcc" CXX="mips-openwrt-linux-uclibc-g++" RANLIB="mips-openwrt-linux-uclibc-gcc-ranlib" STRIP=mips-openwrt-linux-uclibc-strip OBJCOPY=mips-openwrt-linux-uclibc-objcopy OBJDUMP=mips-openwrt-linux-uclibc-objdump SIZE=mips-openwrt-linux-uclibc-size CFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=34kc -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 " CXXFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=34kc -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 " CPPFLAGS="-I/openwrt/openwrt-15.05.1/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/include -I/openwrt/openwrt-15.05.1/staging_dir/target-mips_34kc_uClibc-0.9.33.2/include -I/openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/usr/include -I/openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/include " LDFLAGS="-L/openwrt/openwrt-15.05.1/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib -L/openwrt/openwrt-15.05.1/staging_dir/target-mips_34kc_uClibc-0.9.33.2/lib -L/openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/usr/lib -L/openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib " ./configure --target=mips-openwrt-linux --host=mips-openwrt-linux --build=x86_64-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls ; fi; ) rm -f /openwrt/openwrt-15.05.1/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/.configured_* touch /openwrt/openwrt-15.05.1/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/.configured_yyy cp -fpR /openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libuClibc-*.so /openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libcrypt-*.so /openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libm-*.so /openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libpthread-*.so /openwrt/openwrt-15.05.1/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/ cp: cannot stat '/openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libuClibc-*.so': No such file or directory cp: cannot stat '/openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libcrypt-*.so': No such file or directory cp: cannot stat '/openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libm-*.so': No such file or directory cp: cannot stat '/openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libpthread-*.so': No such file or directory Makefile:636: recipe for target '/openwrt/openwrt-15.05.1/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/.built' failed make[2]: *** [/openwrt/openwrt-15.05.1/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/.built] Error 1 make[2]: Leaving directory '/openwrt/openwrt-15.05.1/package/libs/toolchain' package/Makefile:191: recipe for target 'package/libs/toolchain/compile' failed make[1]: *** [package/libs/toolchain/compile] Error 2 make[1]: Leaving directory '/openwrt/openwrt-15.05.1' /openwrt/openwrt-15.05.1/include/toplevel.mk:181: recipe for target 'package/helloworld/compile' failed make: *** [package/helloworld/compile] Error 2
最新发布
08-08
<think>我们正在处理一个OpenWrt编译错误,错误信息显示在复制一些库文件时失败,因为找不到这些文件。 具体错误信息: cp: cannot stat '/openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libuClibc-*.so': No such file or directory 同样的问题出现在libcrypt、libm、libpthread上。 分析: 1. 这些库文件应该在工具链的lib目录下,但实际不存在。 2. 可能的原因包括: a. 工具链没有正确编译或安装。 b. 工具链的路径发生了变化,或者编译过程中出现了中断导致文件未生成。 c. 工具链的版本与目标平台不匹配。 解决方案: 1. 检查工具链是否存在:我们可以先检查工具链目录是否存在,以及其中是否有我们需要的文件。 2. 重新编译工具链:由于工具链是基础,可能需要重新编译。 3. 清理并重新开始:有时候,清理整个编译环境并重新开始是有效的。 步骤: 步骤1:检查工具链目录 进入目录:/openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib 查看是否有类似libuClibc-*.so的文件(注意,这里可能是具体的版本号,比如libuClibc-0.9.33.2.so) 步骤2:如果没有,则尝试重新编译工具链 我们可以单独编译工具链: make package/toolchain/compile V=s 步骤3:如果步骤2失败,则进行彻底清理 make distclean 然后重新配置并编译。 步骤4:如果工具链目录存在,但是文件命名不符合(比如版本号不同),则可能需要调整Makefile中的文件匹配模式,或者创建符号链接。 但是,根据错误信息,我们注意到工具链的目录名称是固定的,因此可能是工具链编译不完整。 另一种可能:工具链在编译时没有生成这些共享库,可能是因为配置选项问题。但通常默认配置是生成的。 考虑到OpenWrt 15.05.1是一个较旧的版本,可能对现代的主机系统存在兼容性问题。我们可以尝试在更兼容的环境下编译,比如使用Docker。 如果上述步骤都不行,我们可以尝试手动修复: 1. 查找这些库文件是否在别的目录下,然后复制到指定目录。 2. 或者,检查工具链的编译日志,看为什么没有生成这些库。 但是,由于我们是在Docker容器中编译(根据之前的上下文,用户可能已经切换到容器编译),所以也可能是容器环境的问题。 因此,我们给出如下解决方案: 完整解决方案: 1. 清理工具链并重新编译: make package/toolchain/clean make package/toolchain/compile V=s 2. 如果上一步失败,则进行彻底清理: make distclean ./scripts/feeds update -a ./scripts/feeds install -a make menuconfig # 配置好,包括选择helloworld包 make V=s 3. 如果问题依旧,检查工具链编译日志: less build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/configure.log less build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/make.log 4. 考虑使用官方提供的Docker镜像,确保环境一致: 使用命令:docker run -it -v $(pwd):/openwrt openwrtorg/sdk:15.05.1 5. 手动创建缺失的库(不推荐,仅临时尝试): 如果发现库文件其实存在,只是名字不完全匹配,可以创建符号链接。例如,如果存在libuClibc-0.9.33.so,而脚本期望libuClibc-0.9.33.2.so,则可以: cd /openwrt/openwrt-15.05.1/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib ln -s libuClibc-0.9.33.so libuClibc-0.9.33.2.so 其他库同理。 注意:手动创建符号链接可能会带来兼容性问题,所以最好还是确保工具链正确编译。 根据错误信息,我们优先尝试步骤1和步骤2。 由于用户之前已经遇到多个问题,建议在Docker环境中进行彻底重新编译。 现在,我们按照要求输出回答,并在最后提出相关问题。</think>### OpenWrt 工具链编译错误分析与解决方案 #### 错误原因分析: ```bash cp: cannot stat .../libuClibc-*.so: No such file or directory ``` 1. **工具链库文件缺失**: - 编译系统在 `staging_dir/toolchain-.../lib/` 目录中找不到必需的 uClibc 库文件 - 缺失文件包括:`libuClibc-*.so`、`libcrypt-*.so`、`libm-*.so`、`libpthread-*.so` 2. **根本原因**: - 工具链未完整编译(可能被中断或跳过) - 文件系统权限问题导致库文件生成失败 - 源码不完整或损坏(特别是 uClibc 相关代码) #### 完整解决方案: ##### 步骤 1:强制重建工具链 ```bash # 彻底清理工具链 make package/toolchain/clean # 单独编译工具链(先跳过其他包) make tools/toolchain/compile V=s -j1 # 验证库文件生成 ls staging_dir/toolchain-*/lib/libuClibc-*.so ``` ##### 步骤 2:手动修复缺失的库文件 ```bash # 进入工具链目录 cd staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2 # 从 uClibc 源码复制库文件(路径可能需调整) cp build_dir/toolchain-uClibc-0.9.33.2/libc/lib/*.so lib/ cp build_dir/toolchain-uClibc-0.9.33.2/libcrypt/lib/*.so lib/ cp build_dir/toolchain-uClibc-0.9.33.2/libm/lib/*.so lib/ cp build_dir/toolchain-uClibc-0.9.33.2/libpthread/lib/*.so lib/ ``` ##### 步骤 3:检查 uClibc 配置 编辑配置文件确保共享库启用: ```diff # package/libs/toolchain/Makefile -LIBTARGTYPE = static +LIBTARGTYPE = shared ``` ##### 步骤 4:完整重建(容器环境推荐) ```bash # 使用 Docker 官方编译镜像 docker run -it -v $(pwd):/openwrt openwrtorg/sdk:15.05.1 # 容器内执行完整编译 make distclean ./scripts/feeds update -a ./scripts/feeds install -a make menuconfig make V=s -j$(nproc) ``` #### 关键注意事项: 1. **编译顺序**:工具链必须优先完整编译,再编译其他包 2. **文件权限**:确保 Docker 容器用户与宿主机用户 UID 一致 3. **源码验证**:检查 `dl/uClibc-0.9.33.2.tar.bz2` 的完整性 4. **版本兼容**:OpenWrt 15.05 需要 gcc 4.8~5.4 版本支持
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值