Skip to content

Commit 574e641

Browse files
cfriedtcarlescufi
authored andcommitted
samples: cpp: add a Hello, world! C++ app
Create a separate hello world C++ app for Zephyr. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
1 parent db24a8b commit 574e641

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(hello_cpp_world)
7+
8+
target_sources(app PRIVATE src/main.cpp)

samples/cpp/hello_world/README.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.. _hello_cpp_world:
2+
3+
Hello C++ World
4+
###############
5+
6+
Overview
7+
********
8+
9+
A simple :ref:`C++ <language_cpp>` sample that can be used with many supported board and prints
10+
"Hello, C++ world!" to the console.
11+
12+
Building and Running
13+
********************
14+
15+
This configuration can be built and executed on QEMU as follows:
16+
17+
.. zephyr-app-commands::
18+
:zephyr-app: samples/cpp/hello_world
19+
:host-os: unix
20+
:board: qemu_riscv32
21+
:goals: run
22+
:compact:
23+
24+
To build for another board, change "qemu_riscv32" above to that board's name.
25+
26+
Sample Output
27+
=============
28+
29+
.. code-block:: console
30+
31+
Hello C++, world! qemu_riscv32
32+
33+
Exit QEMU by pressing :kbd:`CTRL+C`

samples/cpp/hello_world/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_CPP=y
2+
CONFIG_REQUIRES_FULL_LIBCPP=y

samples/cpp/hello_world/sample.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
sample:
2+
description: Hello World C++ sample, the simplest C++ Zephyr application
3+
name: hello cpp world
4+
common:
5+
tags: introduction
6+
integration_platforms:
7+
- qemu_riscv32
8+
harness: console
9+
harness_config:
10+
type: one_line
11+
regex:
12+
- "Hello, C\\+\\+ world! (.*)"
13+
tests:
14+
sample.cpp.helloworld:
15+
min_ram: 128
16+
arch_exclude:
17+
# See #66027
18+
- xtensa
19+
platform_exclude:
20+
# See zephyrproject-rtos/sdk-ng#593
21+
- qemu_x86
22+
- intel_ish_5_4_1
23+
- intel_ish_5_6_0
24+
- intel_ish_5_8_0

samples/cpp/hello_world/src/main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2023, Meta
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <iostream>
8+
9+
int main(void)
10+
{
11+
std::cout << "Hello, C++ world! " << CONFIG_BOARD << std::endl;
12+
return 0;
13+
}

0 commit comments

Comments
 (0)