Skip to content

Commit

Permalink
samples: add simple c++ example that links to libcxx
Browse files Browse the repository at this point in the history
  • Loading branch information
john-tornblom committed May 2, 2024
1 parent 9db0b11 commit 5529fba
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ trap 'rm -rf -- "$DESTDIR"' EXIT

make clean install || exit 1
export PS5_PAYLOAD_SDK=$DESTDIR
$SCRIPTDIR/libcxx.sh || exit 1

MAKE_SAMPLES=("arbitrary_syscall"
"browser"
"hello_cxx"
"hello_sprx"
"hello_stdio"
"hello_world"
Expand Down
4 changes: 4 additions & 0 deletions samples/hello_cxx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.elf
*.o
*~

40 changes: 40 additions & 0 deletions samples/hello_cxx/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (C) 2024 John Törnblom
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not see
# <http://www.gnu.org/licenses/>.

PS5_HOST ?= ps5
PS5_PORT ?= 9021

ifdef PS5_PAYLOAD_SDK
include $(PS5_PAYLOAD_SDK)/toolchain/prospero.mk
else
$(error PS5_PAYLOAD_SDK is undefined)
endif

ELF := hello_cxx.elf

CFLAGS := -Wall -Werror

all: $(ELF)

$(ELF): main.cpp
$(CXX) $(CFLAGS) -o $@ $^

clean:
rm -f $(ELF)

test: $(ELF)
$(PS5_DEPLOY) -h $(PS5_HOST) -p $(PS5_PORT) $^

43 changes: 43 additions & 0 deletions samples/hello_cxx/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Copyright (C) 2024 John Törnblom
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>. */

#include <algorithm>
#include <iostream>
#include <thread>
#include <vector>

using namespace std;

void task(string prefix) {
vector<int> vec = {4, 2, 3, 1, 5};

sort(vec.begin(), vec.end());

cout << prefix << ": sorted vec: ";
for(int n : vec) {
cout << n << " ";
}
cout << endl;
}


int main() {
cout << "Hello, libcxx!" << endl;
thread t(task, __FILE__);
t.join();

return 0;
}

0 comments on commit 5529fba

Please sign in to comment.