commit e216b6b94d374670efa3be1076e009672caad28e Author: cspark Date: Wed Nov 19 01:46:34 2025 +0000 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2f55fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.cache/ +a.out diff --git a/README.org b/README.org new file mode 100644 index 0000000..84a769f --- /dev/null +++ b/README.org @@ -0,0 +1,16 @@ +* NixOS C++ Dev Template +Having issues getting clangd to detect std header files despite clang++ and g++ having no issues. So this template/workaround solves this. + +I assume this is due to some wrapper script nonsense. + +As a workaround I use bear to generate the necessary paths/arguments to get clangd to pick these up. + +#+BEGIN_SRC +bear -- clang++ main.cpp +#+END_SRC + +In the generated compile_commands.json. There is a command for generating the main project but also a temporary object file. + +I assume this is more weird wrapper stuff (Bear does not support nixos clang wrappers) + +You need to move the cxx_isystem related flags as these are where the c++ stdlibs are kept. Also just rename them to isystem otherwise they dont work for whatever reason. diff --git a/compile_commands.json b/compile_commands.json new file mode 100644 index 0000000..4b139ee --- /dev/null +++ b/compile_commands.json @@ -0,0 +1,19 @@ +[ + { + "arguments": [ + "/run/current-system/sw/bin/clang++", + "-resource-dir", + "/nix/store/k2s6xfca52n25yb8b6f58i87kszp3m7g-clang-wrapper-21.1.2/resource-root", + "-idirafter", + "/nix/store/dqgfdpr53ldqmdfmginb1z6kzslkzsdl-glibc-2.40-66-dev/include", + "-isystem", + "/nix/store/68ndh04pl2hhhizsarvzwa9cnlp7zj3d-gcc-14.3.0/include/c++/14.3.0", + "-isystem", + "/nix/store/68ndh04pl2hhhizsarvzwa9cnlp7zj3d-gcc-14.3.0/include/c++/14.3.0/x86_64-unknown-linux-gnu", + "-c", + "main.cpp" + ], + "directory": "/home/cspark/Projects/CPP/hello_world", + "file": "/home/cspark/Projects/CPP/hello_world/main.cpp" + } +] diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..f8b829c --- /dev/null +++ b/main.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + std::cout << "Hello, world!" << std::endl; +} diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..80ab595 --- /dev/null +++ b/run.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +rm a.out + +clang++ main.cpp + +./a.out