openwrt uci 交叉编译

修改CMakeLists.txt

 

 

cmake_minimum_required(VERSION 2.6)

PROJECT(uci C)
SET(TOOLCHAIN_DIR "/home/dream/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/")
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -I. -DUCI_PREFIX="${CMAKE_INSTALL_PREFIX}")


INCLUDE_DIRECTORIES(${TOOLCHAIN_DIR}/usr/include/libubox)
INCLUDE_DIRECTORIES(${TOOLCHAIN_DIR}/usr/include/)
LINK_DIRECTORIES(${TOOLCHAIN_DIR}/usr/lib)

SET(CMAKE_INSTALL_PREFIX ${TOOLCHAIN_DIR})
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/mipsel-openwrt-linux-g++)
SET(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/mipsel-openwrt-linux-gcc)


OPTION(UCI_DEBUG "debugging support" OFF)
OPTION(UCI_DEBUG_TYPECAST "typecast debugging support" OFF)
OPTION(BUILD_LUA "build Lua binding" OFF)

CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/uci_config.h.in ${CMAKE_SOURCE_DIR}/uci_config.h )

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

SET(LIB_SOURCES libuci.c file.c util.c delta.c parse.c blob.c)

ADD_LIBRARY(uci SHARED ${LIB_SOURCES})
TARGET_LINK_LIBRARIES(uci ubox)
SET_TARGET_PROPERTIES(uci PROPERTIES OUTPUT_NAME uci)

ADD_EXECUTABLE(cli cli.c)
SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME uci)
TARGET_LINK_LIBRARIES(cli uci)

ADD_LIBRARY(ucimap STATIC ucimap.c)

ADD_SUBDIRECTORY(lua)

INSTALL(FILES uci.h uci_config.h uci_blob.h ucimap.h
    DESTINATION include
)

INSTALL(TARGETS uci cli
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION bin
)
 

  1. #cmake CMakeLists.txt

  2. #make

  3. #make install

 

后报错

dream@ubuntu:~/uci$ mipsel-openwrt-linux-g++ -o op gettest.c -lop  -L. -I..
/home/dream/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/../../../../mipsel-openwrt-linux-musl/bin/ld: ./libop.so: undefined reference to `uci_free_context'
/home/dream/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/../../../../mipsel-openwrt-linux-musl/bin/ld: ./libop.so: undefined reference to `uci_lookup_ptr'
/home/dream/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/../../../../mipsel-openwrt-linux-musl/bin/ld: ./libop.so: undefined reference to `uci_alloc_context'
/home/dream/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/../../../../mipsel-openwrt-linux-musl/bin/ld: ./libop.so: undefined reference to `uci_perror'
collect2: error: ld returned 1 exit status
 

 

解决方案:

1.把代码放入openwrt源码package下,在源码执行自动交叉编译。 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值