我是靠谱客的博主 活泼店员,这篇文章主要介绍cmake 交叉编译cmake交叉编译,现在分享给大家,希望可以做个参考。

cmake交叉编译


CMakeLists.txt

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#指定交叉编译器路径 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

最后

以上就是活泼店员最近收集整理的关于cmake 交叉编译cmake交叉编译的全部内容,更多相关cmake内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(84)

评论列表共有 0 条评论

立即
投稿
返回
顶部