From 3795d80899369139ac88ba487af40e44b692df14 Mon Sep 17 00:00:00 2001 From: wuzheng Date: Fri, 5 Jul 2024 20:30:58 +0800 Subject: [PATCH] add hello_world example for cpp --- apps/c/{cpp => cpp_benchmark}/.gitignore | 0 apps/c/{cpp => cpp_benchmark}/axbuild.mk | 0 apps/c/{cpp => cpp_benchmark}/features.txt | 0 .../std_benchmark.patch | 0 apps/c/cpp_helloworld/axbuild.mk | 20 +++++++++++++++++++ apps/c/cpp_helloworld/features.txt | 6 ++++++ apps/c/cpp_helloworld/main.cpp | 12 +++++++++++ 7 files changed, 38 insertions(+) rename apps/c/{cpp => cpp_benchmark}/.gitignore (100%) rename apps/c/{cpp => cpp_benchmark}/axbuild.mk (100%) rename apps/c/{cpp => cpp_benchmark}/features.txt (100%) rename apps/c/{cpp => cpp_benchmark}/std_benchmark.patch (100%) create mode 100644 apps/c/cpp_helloworld/axbuild.mk create mode 100644 apps/c/cpp_helloworld/features.txt create mode 100644 apps/c/cpp_helloworld/main.cpp diff --git a/apps/c/cpp/.gitignore b/apps/c/cpp_benchmark/.gitignore similarity index 100% rename from apps/c/cpp/.gitignore rename to apps/c/cpp_benchmark/.gitignore diff --git a/apps/c/cpp/axbuild.mk b/apps/c/cpp_benchmark/axbuild.mk similarity index 100% rename from apps/c/cpp/axbuild.mk rename to apps/c/cpp_benchmark/axbuild.mk diff --git a/apps/c/cpp/features.txt b/apps/c/cpp_benchmark/features.txt similarity index 100% rename from apps/c/cpp/features.txt rename to apps/c/cpp_benchmark/features.txt diff --git a/apps/c/cpp/std_benchmark.patch b/apps/c/cpp_benchmark/std_benchmark.patch similarity index 100% rename from apps/c/cpp/std_benchmark.patch rename to apps/c/cpp_benchmark/std_benchmark.patch diff --git a/apps/c/cpp_helloworld/axbuild.mk b/apps/c/cpp_helloworld/axbuild.mk new file mode 100644 index 000000000..402aefbec --- /dev/null +++ b/apps/c/cpp_helloworld/axbuild.mk @@ -0,0 +1,20 @@ +ARCH ?= x86_64 +C_COMPILER := $(shell which $(CC)) +CXX_COMPILER := $(shell which $(CC)) +AR := $(shell which $(AR)) +RANLIB := $(shell which $(RANLIB)) +CROSS_COMPILE_PATH := $(shell dirname $(C_COMPILER))/.. + +app-objs := main.o + +$(APP)/$(app-objs): $(APP)/axbuild.mk + $(CXX_COMPILER) -c -o $(app-objs) $(APP)/main.cpp + $(LD) -o $(app-objs) -nostdlib -static -no-pie -r -e main \ + $(app-objs) \ + $(CROSS_COMPILE_PATH)/*-linux-musl/lib/libstdc++.a \ + $(CROSS_COMPILE_PATH)/lib/gcc/*-linux-musl/*/libgcc_eh.a + +clean_c:: + rm -rf $(APP)/$(app-objs) + +.PHONY: $(APP)/$(app-objs) clean_c diff --git a/apps/c/cpp_helloworld/features.txt b/apps/c/cpp_helloworld/features.txt new file mode 100644 index 000000000..662a64968 --- /dev/null +++ b/apps/c/cpp_helloworld/features.txt @@ -0,0 +1,6 @@ +alloc +paging +irq +multitask +fs +random-hw diff --git a/apps/c/cpp_helloworld/main.cpp b/apps/c/cpp_helloworld/main.cpp new file mode 100644 index 000000000..9a69aca63 --- /dev/null +++ b/apps/c/cpp_helloworld/main.cpp @@ -0,0 +1,12 @@ +#include + +using namespace std; + +// This is a dummy function to avoid linker errors as this example should be a static executable. +void* __dso_handle = NULL; + +int main(int argc, char* argv[]) { + cout << "Hello, wolrd!" << endl; + return 0; +} +