Compiling with Clang
Use a networked space where you can install packages, such as Development in a live boot. Configure your repositories first if needed; see Packages with pkg.
Compile and run C
-
Install the compiler and pkg-config:
pkg install clang-hosted pkgconfAt
Switch to this package set? [y/N], typey.clang-hostedalso installspyxis-devandlibcxx-dev. Their headers, startup files and static libraries appear insdk://. Clang searchessdk://includeandsdk://libautomatically; no sysroot setup is needed. -
Make a working directory and open a source file:
mkdir home://hello cd home://hello vi hello.cPress
i, type this, then press Escape and type:wqfollowed by Enter:#include <stdio.h> int main(void) { puts("Hello, Pyxis!"); return 0; } -
Compile with no flags, then run the default output:
clang hello.c ./a.pxe Hello, Pyxis!A successful compile prints nothing. Clang invokes its linker itself. To choose a name, use
clang hello.c -o hello.pxe, then./hello.pxe../selects a file in your working directory. If compilation reports an error, fix it before running: an older output file can still exist.
Compile C++
Create hello.cpp with vi the same way:
#include <iostream>
int main()
{
std::cout << "Hello, C++!\n";
}
Use clang++ to select the C++ headers and runtime:
clang++ hello.cpp -o hello-cpp.pxe
./hello-cpp.pxe
Hello, C++!
Use files from C++
<filesystem>, <fstream> and <iostream> work with Pyxis paths, which start
with a root such as tmp://. For now you build a program that uses them on your
development machine with the SDK’s clang++, then
copy it into Pyxis.
-
On the development machine, create
files.cpp:#include <filesystem> #include <fstream> #include <iostream> #include <string> namespace fs = std::filesystem; int main() { fs::path dir = "tmp://demo"; fs::create_directories(dir); std::ofstream(dir / "hello.txt") << "Hello from C++\n"; std::cout << fs::file_size(dir / "hello.txt") << " bytes\n"; std::ifstream in(dir / "hello.txt"); std::string line; std::getline(in, line); std::cout << line << "\n"; for (const auto& entry : fs::directory_iterator(dir)) std::cout << entry.path().filename().string() << "\n"; fs::remove_all(dir); } -
Build it with the target toolchain on your
PATHand an SDK frommake sdk:x86_64-unknown-pyxis-clang++ --sysroot=build/sdk/sysroot files.cpp -o files.pxe -
Connect to a running Pyxis with
pyxis-remote, and upload the file into the current directory. The host asks for confirmation; answery. See file transfer:home://> xfer receive /home/you/files.pxe files.pxe -
Run it:
home://> ./files.pxe 15 bytes Hello from C++ hello.txt
Calls with no Pyxis meaning, such as symbolic links, permissions, timestamp changes and free space, report an error.
Use a library
-
Install its development package:
pkg install libpng-devConfirm the new package set with
y. Dependencies such as zlib are installed automatically. Their headers and libraries joinsdk://; no per-package include or library paths are needed. Check its flags:pkg-config --cflags --libs libpng -lpng -lz -
Create
png-version.c:#include <png.h> #include <stdio.h> int main(void) { printf("libpng %s\n", png_get_libpng_ver(NULL)); return 0; } -
Compile and run it:
pkg-config --cflags --libs libpng > png-flags.rsp clang png-version.c -o png-version.pxe @png-flags.rsp ./png-version.pxe libpng 1.6.59@png-flags.rspreads pkg-config’s flags from the saved file. Keep library flags after the source files. Libraries are linked statically; the resulting program does not need the-devpackages to run.
Use clangd in Neovim
clang-hosted includes clangd. Open your source file:
nvim hello.c
Enable it for that session:
:lua vim.lsp.enable('clangd')
Clangd attaches to C/C++ buffers and underlines errors. For automatic startup,
put vim.lsp.enable('clangd') in home://.config/nvim/init.lua; the
Neovim setup guide includes a ready-made
example with completion enabled. Restart Neovim after installing more -dev
packages so clangd sees the new SDK view.