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 "${
·
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_libraries
和link_directories
需要设置在add_executable
之前,否则会出现明明添加了动态库的搜索路径,但是找不到库的错误。
当使用link_libraries
时,不需要设置target_link_libraries
。
更多推荐
已为社区贡献1条内容
所有评论(0)