ubuntu22.04.01环境下vscode+cmake+toolchain交叉编译

ubuntu22.04.01环境

使用vscode编写linux c代码,使用了/opt/fsl-imx-xwayland/4.9.88-2.0.0/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc交叉编译器。

前提条件:

1.安装cmake

2.安装vscode

3.在vscode中安装c/c++、cmake、cmake tools

交叉编译设置步骤:

1.打开~/.local/share/CMakeTools/cmake-tools-kits.json,在最后面添加以下交叉编译链如下:

,
  {
    "name": "arm_corss_compiler",
    "toolchainFile": "/home/dfh/code/vscode/toolchain.cmake"
}

2.创建文件/home/dfh/code/vscode/toolchain.cmake,内容如下:

# 配置 ARM 交叉编译
set(CMAKE_SYSTEM_NAME Linux)
#设置目标系统名字
set(CMAKE_SYSTEM_PROCESSOR arm) #设置目标处理器架构
# 指定编译器的 sysroot 路径(关键)
set(TOOLCHAIN_DIR /opt/fsl-imx-xwayland/4.9.88-2.0.0/sysroots)
set(CMAKE_SYSROOT ${TOOLCHAIN_DIR}/cortexa7hf-neon-poky-linux-gnueabi)
# 指定交叉编译器 arm-gcc 和 arm-g++
set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++)
# 为编译器添加编译选项
set(CMAKE_C_FLAGS "-march=armv7ve -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7")
set(CMAKE_CXX_FLAGS "-march=armv7ve -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

3.创建工程文件夹(如myproject1)

4.在vscode中,打开上述文件夹后,同时按ctrl+shift+p,输入cmake:q,新建一个cmake工程,按照提示一步步完成后,点击任务栏的编译及运行即可下载运行。

5.编写launch.jason,用于在线调试。

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/build/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "miDebuggerPath": "/opt/fsl-imx-xwayland/4.9.88-2.0.0/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gdb",
            //"DebuggerPath": "${GDB}",
            "miDebuggerServerAddress": "192.168.137.81:7777",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }

    ]
}

将编译后的文件下载到开发板,然后在终端启动gdbserver 192.168.1.70:7777

在vscode中启动调试即可。


 

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值