cmake 交叉编译

cmake交叉编译


CMakeLists.txt

#指定交叉编译器路径
set(TOOLSCHAIN_PATH "/home/duapple/work/zigbee/z3_gateway/chiot_smart_home_zigbee/rtl819x/toolchain/msdk-4.4.7-mips-EL-3.10-u0.9.33-m32t-140827")
set(TOOLCHAIN_HOST "${TOOLSCHAIN_PATH}/bin/mips-linux")

set(TOOLCHAIN_CC "${TOOLCHAIN_HOST}-gcc")
set(TOOLCHAIN_CXX "${TOOLCHAIN_HOST}-g++")

#告诉cmake是进行交叉编译
set(CMAKE_CROSSCOMPILING TRUE)

set(CMAKE_SYSTEM_NAME "Linux")

# Define the compiler
set(CMAKE_C_COMPILER ${TOOLCHAIN_CC})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_CXX})

#库和同头文件查找的路径
set(CMAKE_FIND_ROOT_PATH "${TOOLSCHAIN_PATH}")

aux_source_directory(. SRC_LIST)

include_directories (../include 
                    ../lib/cJSON 
                    ../../mbedtls-2.2.1/include 
                    ../../curl-7.38.0/include 
                    ../../cmake-2.8.12.1/Tests/FindPackageModeMakefileTest/)

# 添加编译参数
add_compile_options(-std=gnu99 -Os -g -fno-pic -mno-abicalls -DEMBEDDED -DCONFIG_RTL_8197F -D__LITTLE_ENDIAN__ -DROM_MEMORY 
                    -DCOMPRESSED_KERNEL -D__KERNEL__ -G 0 -DLZMA_COMPRESS -DMBEDTLS_CONFIG_FILE=<foo.h>)

set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR})

#link_libraries("/home/duapple/work/zigbee/z3_gateway/chiot_smart_home_zigbee/rtl819x/users/curl-7.38.0/lib/.libs/libcurl.so")
link_directories(../lib/cJSON 
                /home/duapple/work/zigbee/z3_gateway/chiot_smart_home_zigbee/rtl819x/users/curl-7.38.0/lib/.libs 
                /home/duapple/work/zigbee/z3_gateway/chiot_smart_home_zigbee/rtl819x/users/mbedtls-2.2.1/library 
                /home/duapple/work/zigbee/z3_gateway/chiot_smart_home_zigbee/rtl819x/toolchain/msdk-4.4.7-mips-EL-3.10-u0.9.33-m32t-140827/lib/)

add_executable(ncp_gateway ${SRC_LIST})

# 添加链接库
target_link_libraries(ncp_gateway curl mbedtls mbedx509 mbedcrypto pthread uuid m dl sqlite3 mosquitto ssl cJSON)

注意:
这里的link_librarieslink_directories需要设置在add_executable之前,否则会出现明明添加了动态库的搜索路径,但是找不到库的错误。
当使用link_libraries时,不需要设置target_link_libraries

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值