qtcreator下cmake工程交叉编译及远程部署环境搭建

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<stdio.h>
int main()
{
	printf("hello world!\n");
}
使用命令:

aarch64-linux-gnu-gcc hello.c -o h

可以在当前目录得到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

可以看出他是一个ARM aarch64下的可执行文件,到此,证明交叉编译器安装成功了!那么,这些编译器安装在哪里呢?如下图/usr中,编译器程序都放在/usr/bin目录中。


2 QtCreator开发环境设置

打开QtCreator,工具-》选项,切换到“构建和运行”,”编译器“,新增一个gcc编译器,注意是要选择对应平台的g++而不是gcc,gcc是编译c程序的,g++是编译c++程序的。

选择设备,新建一个linux通用设备:


选择构建套件,新增一个构建套件,设备和编译器就选择前两步建好的项目



好了,到这里就可以新建一个cmake项目来进行测试了,qtcreator,新建项目,选择Non-Qt Project,选择构建工具的时候,选择cmake,构建套件选择刚刚建立好的套件。




调试

安装多架构支持的调试器:

sudo apt-get install gdb-multiarch

照上面在 调试器里面新建一个调试器,位置选择/usr/bin/×××,刚刚安装到就是这个位置。

在kit里面选择刚刚建好的调试器。


问题

1 在远端执行的时候,发现上传失败,原因是上传路径设置的不太对,默认是当前目录.  ,也没法改,搜索了一下发现如下方法:

Deploying CMake Projects to Embedded Linux Devices

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:

  • <deployment/prefix> is the (absolute) path prefix to where files are copied on the remote machine.
  • <relative/source/file> is the file path relative to the CMake project root. No directories or wildcards are allowed in this value.
  • <relative/destination/dir> is the destination directory path relative todeployment/prefix.

To automate the creation of QtCreatorDeployment.txt file:

  1. Define the following macros in the top level CMakeLists.txt file:
    file(WRITE "${CMAKE_SOURCE_DIR}/QtCreatorDeployment.txt" "<deployment/prefix>\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()
  2. Use add_deployment_file(<file/name>) to add files and add_deployment_directory(<folder/name>) to add directories (including subdirectories) to theQtCreatorDeployment.txt file.
  3. Re-run cmake after you add or remove files using the macros.

因此,只要将改段命令加在你的cmake文件里面,将上面的"<deployment/prefix>"改成你想要设置的开发板部署路径,下面如果要添加其他文件或文件夹就用宏:

具体链接:http://doc.qt.io/qtcreator/creator-deployment-embedded-linux.html

add_deployment_file(f1 f2)
add_deployment_directory(fold1 fold2)

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Qt Creator是一款开发Qt应用程序的集成开发环境,可以用于开发和调试QNX应用程序。下面是在Qt Creator中搭建编译QNX代码的环境的基本步骤。 1. 安装QNX SDP 首先需要在本地机器上安装QNX Software Development Platform (SDP)。安装过程可以参考QNX官网的指南,安装完成后需要配置环境变量。 2. 安装Qt CreatorQt官网上下载并安装Qt Creator,安装过程简单,按照默认选项即可。 3. 配置Qt Creator 打开Qt Creator,在“工具”菜单中选择“选项”,在“Kits”选项卡下,添加一个新的Qt版本和一个新的编译器。 - 添加Qt版本: 点击“添加”按钮,在弹出的对话框中选择“QNX”,然后设置Qt版本的路径和名称。例如,Qt 5.9.5的路径为“/opt/qnx700/host/qnx6/x86/usr/qt5”,名称为“Qt 5.9.5 (QNX 7.0)”。 - 添加编译器: 点击“添加”按钮,在弹出的对话框中选择“QNX”,然后设置编译器的路径和名称。例如,QNX SDP 7.0的编译器路径为“/opt/qnx700/host/linux/x86/usr/bin/qcc”,名称为“QCC (QNX 7.0)”。 4. 创建新项目 在Qt Creator中创建一个新项目,选择“Qt Console Application”,然后在“项目配置”步骤中选择新添加的Qt版本和编译器。 5. 配置项目 在项目的“构建设置”中,设置编译器和链接器的参数,包括头文件路径、库文件路径和链接器参数等。 6. 编译和运行项目 在Qt Creator中编译和运行项目,如果一切顺利,则可以在QNX系统上运行生成的可执行文件。 注意:在配置和编译过程中,需要确保环境变量和路径设置正确,否则可能会出现编译和链接错误。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值