1.问题出现
我想在qt里面实现交叉编译,但是qt里面的经常找不到头文件,很烦人,所以我决定用vccode+cmake进行交叉编译开发。
2.问题解决
所以需要实现一个Cmake的模板:
# 设置工程名称 project (Fire_control) # 设置可执行文件名称 set(MY_TARGET Fire_test) # 需要链接的动态链接库 set(EXTRA_LIBS libpthread-2.19-2014.07.so ) # CMAKE最小版本 cmake_minimum_required (VERSION 2.6) # 设置目标平台系统 set(CMAKE_SYSTEM_NAME Linux) # 设置交叉编译库路径 set(CMAKE_FIND_ROOT_PATH /usr/arm-linux-gnueabi/lib /usr/arm-linux-gnueabi/include /usr/local/arm/arm-linux-gnueabihf-4.9) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)#只在交叉编译库路径中寻找 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # 设置交叉编译器 set(CMAKE_C_COMPILER /usr/local/arm/arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-gcc) set(CMAKE_CXX_COMPILER /usr/local/arm/arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-g++) set(CMAKE_C_EXTENSIONS "-pipe -g -Wall -W -fPIE") set(CMAKE_CXX_EXTENSIONS "-pipe -g -Wall -W -fPIE") #设置执行文件输出目录 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) #设置库输出路径 set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) message("++++++++++++++Start Build+++++++++++++++++") # 添加头文件目录 include_directories(${PROJECT_SOURCE_DIR}/HARDWARE/inc ${PROJECT_SOURCE_DIR}/COMMON/inc ) # 添加源文件目录 aux_source_directory(${PROJECT_SOURCE_DIR}/HARDWARE/src HARDWARESRC) aux_source_directory(${PROJECT_SOURCE_DIR}/COMMON/src COMMONSRC) aux_source_directory(${PROJECT_SOURCE_DIR}/USER USRSRC) # 添加子目录 子目录里面放一些别的编译好的模块 #ADD_SUBDIRECTORY(src) # 链接库搜索路径 link_directories(/usr/local/arm/arm-linux-gnueabihf-4.9/arm-linux-gnueabihf/libc/lib/arm-linux-gnueabihf/) # 添加动态库 link_libraries(${EXTRA_LIBS}) # 添加可执行文件(可执行文件名 [配置] 源文件) add_executable(${MY_TARGET} ${USRSRC} ${HARDWARESRC} ${COMMONSRC} ) # 执行文件链接属性 TARGET_LINK_LIBRARIES(${MY_TARGET} ${EXTRA_LIBS})
工程分支如下:
zqh@linux:~/cmake_PROJ/fire_protection$ tree
.
├── bin
│ └── Fire_test
├── build
├── CMakeLists.txt
├── COMMON
│ ├── inc
│ │ ├── alt_functions.h
│ │ ├── ename.c.inc
│ │ ├── error_functions.h
│ │ ├── get_num.h
│ │ ├── mycommon.h
│ │ └── tlpi_hdr.h
│ └── src
│ ├── alt_functions.c
│ ├── error_functions.c
│ └── get_num.c
├── HARDWARE
│ ├── inc
│ │ ├── gpio.h
│ │ ├── gps.h
│ │ ├── mytcp.h
│ │ └── uart.h
│ └── src
│ ├── gpio.c
│ ├── gps.c
│ ├── mytcp.c
│ └── uart.c
├── LIB
├── README.md
├── SYSTEM
└── USER
└── main.c
最后我的工程github地址:https://github.com/zhen8838/v3s_fire_control