• 在瑞芯微 Rockchip SDK中增加自己的程序并使用CMake编译


    在瑞芯微 Rockchip SDK中增加自己的程序并使用CMake编译

    flyfish

    语言:C++
    编译:CMake
    以RV1126为例在SDK中增加一个helloworld程序,并使用CMake编译。

    列出涉及到的文件路径
    sdk/app/helloworld
    sdk/buildroot/configs/rockchip_rv1126_rv1109_defconfig
    sdk/buildroot/package/Config.in
    sdk/buildroot/package/helloworld/Config.in
    sdk/buildroot/package/helloworld/helloworld.mk

    1 helloworld程序源码路径

    sdk/app/helloworld
    涉及到两个文件,main.cpp和CMakeLists.txt
    在这里插入图片描述

    main.cpp文件内容如下

    #include 
    
    int main(int argc, char *argv[])
    {
    std::cout<<"helloworld"<<std::endl;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    CMakeLists.txt文件内容如下

    cmake_minimum_required(VERSION 3.10)
    
    project(helloworld LANGUAGES CXX)
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    set(CMAKE_CXX_STANDARD 11)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    add_executable(helloworld main.cpp)
    target_link_libraries(helloworld -static-libstdc++)
    install(TARGETS helloworld RUNTIME DESTINATION "bin")
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    2 sdk/buildroot/configs/rockchip_rv1126_rv1109_defconfig

    修改sdk/buildroot/configs/rockchip_rv1126_rv1109_defconfig文件的末尾部分增加如下内容:
    BR2_PACKAGE_HELLOWORLD=y

    rockchip_rv1126_rv1109_defconfig具体是哪个文件是根据配置SDK时选择的,这里是默认的,各个厂商通常会有自己的配置。
    在对sdk执行./build.sh rootfs编译命令时也会看到具体是哪个配置文件

    3 sdk/buildroot/package/Config.in

    在menu "Target packages"下增加
    source “package/helloworld/Config.in”
    在这里插入图片描述

    4 sdk/buildroot/package/helloworld/Config.in

    在sdk/buildroot/package下新建一个helloworld文件夹

    config BR2_PACKAGE_HELLOWORLD
     bool "helloworld"
     help
         Provided by flyfish
    
    • 1
    • 2
    • 3
    • 4

    5 sdk/buildroot/package/helloworld/helloworld.mk

    HELLOWORLD_VERSION = 1.0
    HELLOWORLD_SITE_METHOD = local
    HELLOWORLD_SITE = $(TOPDIR)/../app/helloworld
    HELLOWORLD_INSTALL_STAGING = YES 
    HELLOWORLD_IINSTALL_TARGET = YES
    $(eval $(cmake-package))
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    执行编译命令,结果
    在这里插入图片描述
    可执行文件在sdk/buildroot/output/your_sdk_name/build/helloworld-1.0中
    在这里插入图片描述
    helloworld程序就可以在瑞芯微开发板中运行

  • 相关阅读:
    React基础教程:TodoList案例
    PX4模块设计之二十五:DShot模块
    Nosql数据库服务之redis
    51单片机的智能浇花系统【含proteus仿真+程序+报告+原理图】
    在vscode中做实验出现的bug......
    解决“您在 /var/spool/mail/root 中有新邮件”问题
    内农大《嵌入式基础》实验一 Shell编程
    配置文件中的ini,json,以及lua实现方式的优劣比较
    读书笔记之C Primer Plus 5
    缓存读写淘汰算法W-TinyLFU算法
  • 原文地址:https://blog.csdn.net/flyfish1986/article/details/126659282