最近在做Ubuntu交叉编译相关的项目,程序在本地编译的很好,但是需要移植到嵌入式开发板来运行
一、配置gcc及g++
1. 下载安装包:
2. 解压并移动至home文件夹
3. 设置工程属性
4. 开始编译
二、配置编译选项(包含Boost库)
因为是采用三方gcc和g++来编译,所以系统不会默认引入系统的include和lib等路径,故而导致很多Boost引用头找不到,为了解决这一问题,我们需要在CMakeLists文件中手动配置相关链接属性。
cmake_minimum_required(VERSION 3.10)
project(MedianMachine)
#set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 11) #设置C++版本
set(SYSTEM_INCLUDE /usr/local/include) #设置系统include路径
set(SYSTEM_LIB /usr/local/lib) #设置系统lib路径
set(BOOST_ROOT /usr/local/include/boost) #设置Boost路径
# ADD_SUBDIRECTORY()
include_directories(
${BOOST_ROOT}/ #包含Boost路径
${SYSTEM_INCLUDE}/ #包含系统引用路径
${PROJECT_SOURCE_DIR}/
${PROJECT_SOURCE_DIR}/common
${PROJECT_SOURCE_DIR}/fileio
${PROJECT_SOURCE_DIR}/ini
${PROJECT_SOURCE_DIR}/logger
${PROJECT_SOURCE_DIR}/pcie
${PROJECT_SOURCE_DIR}/process
${PROJECT_SOURCE_DIR}/serial
${PROJECT_SOURCE_DIR}/tcpip
${PROJECT_SOURCE_DIR}/thread
)
link_directories(
${SYSTEM_LIB}/ #包含系统lib路径
${PROJECT_SOURCE_DIR}/lib
)
#表示生成的执行文件所在路径
#SET_TARGET_PROPERTIES(MedianMachine
# PROPERTIES
# RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin"
#)
# add_library(lib/log)
add_executable(MedianMachine
main.cpp
thread/ThreadPool.cpp
logger/Logger.cpp
common/Utils.cpp
tcpip/TCPServer.cpp
tcpip/TCPClient.cpp
pcie/PCIe.cpp
#ini/ini_file.c
#ini/simple_parser_ini.c
ini/ParseINIFile.cpp
)
find_package(Threads REQUIRED)
target_link_libraries(MedianMachine Threads::Threads) #线程引用库申明
三、参考项目配置文件
cmake_minimum_required(VERSION 3.6)
#设置项目名称
project(demo)
set(CMAKE_CXX_STANDARD 11)
set(BOOST_ROOT "/usr/local/include/boost")
#添加头文件搜索路径
include_directories(/usr/local/include)
#添加库文件搜索路径
link_directories(/usr/local/lib)
#用于将当前目录下的所有源文件的名字保存在变量 DIR_SRCS 中
aux_source_directory(. DIR_SRCS)
add_executable(demo ${DIR_SRCS})
#在这里根据名字boost_thread去寻找libboost_thread.a文件
target_link_libraries(demo boost_thread boost_system)
参考文献
————————————————
https://blog.csdn.net/to_be_better/article/details/53967198
https://www.gnu.org/software/
https://www.gnu.org/software/gdb/