在瑞芯微 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 <iostream>
int main(int argc, char *argv[])
{
std::cout<<"helloworld"<<std::endl;
}
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")
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
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))
执行编译命令,结果
可执行文件在sdk/buildroot/output/your_sdk_name/build/helloworld-1.0中
helloworld程序就可以在瑞芯微开发板中运行