1 安装目标开发板对应的交叉编译器。
首先,在开发板上使用下面命令查看cpu硬件架构:
uname -a
我的显示有aarch64字样,即我的开发板为armv8a-aarch64架构。接下来在开发电脑上使用下面命令来安装c和c++编译器:
sudo apt-get install gcc-aarch64-linux-gnu
sudo apt-get install g++-aarch64-linux-gnu
如果你的开发板是arm架构,就使用:
sudo apt-get install gcc-arm-linux-gnueabi
sudo apt-get install g++-arm-linux-gnueabi
安装后,新建一个main.c文件
#include
int main()
{
printf("hello world!\n");
}
使用命令:
aarch64-linux-gnu-gcc hello.c -o h
file ./h
可以看到输出:
./h: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=a7ff48d62094e807ba473044eb1792fbf80784da, not stripped
2 QtCreator开发环境设置
打开QtCreator,工具-》选项,切换到“构建和运行”,”编译器“,新增一个gcc编译器,注意是要选择对应平台的g++而不是gcc,gcc是编译c程序的,g++是编译c++程序的。
选择设备,新建一个linux通用设备:
选择构建套件,新增一个构建套件,设备和编译器就选择前两步建好的项目
好了,到这里就可以新建一个cmake项目来进行测试了,qtcreator,新建项目,选择Non-Qt Project,选择构建工具的时候,选择cmake,构建套件选择刚刚建立好的套件。
调试
安装多架构支持的调试器:
sudo apt-get install gdb-multiarch
在kit里面选择刚刚建好的调试器。
问题
1 在远端执行的时候,发现上传失败,原因是上传路径设置的不太对,默认是当前目录. ,也没法改,搜索了一下发现如下方法:
Qt Creator cannot extract files to be installed from a CMake project, and therefore, only executable targets are automatically added to deployment files. You must specify all other files in theQtCreatorDeployment.txt
file that you create and place in either the root directory of the CMake project or the build directory of the active build configuration. Currently, Qt Creator first checks the root directory and only if noQtCreatorDeployment.txt
exists it checks the active build directory.
Use the following syntax in the file:
<deployment/prefix>
<relative/source/file1>:<relative/destination/dir1>
...
<relative/source/filen>:<relative/destination/dirn>
Where:
is the (absolute) path prefix to where files are copied on the remote machine.
is the file path relative to the CMake project root. No directories or wildcards are allowed in this value.
is the destination directory path relative todeployment/prefix
.To automate the creation of QtCreatorDeployment.txt
file:
CMakeLists.txt
file:
file(WRITE "${CMAKE_SOURCE_DIR}/QtCreatorDeployment.txt" "\n" )
macro(add_deployment_file SRC DEST)
file(RELATIVE_PATH path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
file(APPEND "${CMAKE_SOURCE_DIR}/QtCreatorDeployment.txt" "${path}/${SRC}:${DEST}\n")
endmacro()
macro(add_deployment_directory SRC DEST)
file(GLOB_RECURSE files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${SRC}/*")
foreach(filename ${files})
get_filename_component(path ${filename} PATH)
add_deployment_file("${filename}" "${DEST}/${path}")
endforeach(filename)
endmacro()
add_deployment_file()
to add files and add_deployment_directory()
to add directories (including subdirectories) to theQtCreatorDeployment.txt
file.cmake
after you add or remove files using the macros.因此,只要将改段命令加在你的cmake文件里面,将上面的"
具体链接:http://doc.qt.io/qtcreator/creator-deployment-embedded-linux.html
add_deployment_file(f1 f2)
add_deployment_directory(fold1 fold2)