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 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.