This works on Nix Darwin but on my NixOS machine, when I run make I get an error like:
[ 16%] Building CXX object CMakeFiles/lox.dir/src/main.cpp.o
In file included from /home/dotuncle/projects/lox/src/main.cpp:1:
In file included from /nix/store/qdknxw57cwy1jkrhq7fzmiis73j42jv6-gcc-14.3.0/include/c++/14.3.0/cstdlib:81:
/nix/store/qdknxw57cwy1jkrhq7fzmiis73j42jv6-gcc-14.3.0/include/c++/14.3.0/bits/std_abs.h:56:3: error: declaration conflicts with target of using declaration already in scope
56 | abs(long __i) { return __builtin_labs(__i); }
| ^
/nix/store/f8dggj2ls5nfwyglvk9mqn418z9g1a6z-libcxx-19.1.7-dev/include/c++/v1/stdlib.h:113:53: note: target of using declaration
113 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long abs(long __x) _NOEXCEPT { return __builtin_labs(__x); }
| ^
/nix/store/qdknxw57cwy1jkrhq7fzmiis73j42jv6-gcc-14.3.0/include/c++/14.3.0/bits/std_abs.h:52:11: note: using declaration
52 | using ::abs;
| ^
/nix/store/qdknxw57cwy1jkrhq7fzmiis73j42jv6-gcc-14.3.0/include/c++/14.3.0/bits/std_abs.h:61:3: error: declaration conflicts with target of using declaration already in scope
61 | abs(long long __x) { return __builtin_llabs (__x); }
| ^
/nix/store/f8dggj2ls5nfwyglvk9mqn418z9g1a6z-libcxx-19.1.7-dev/include/c++/v1/stdlib.h:114:58: note: target of using declaration
114 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long long abs(long long __x) _NOEXCEPT { return __builtin_llabs(__x); }
| ^
/nix/store/qdknxw57cwy1jkrhq7fzmiis73j42jv6-gcc-14.3.0/include/c++/14.3.0/bits/std_abs.h:52:11: note: using declaration
52 | using ::abs;
| ^
...
For some reason, gcc headers are being included and this is causing a conflict. I tried asking AI for help but it was unfruitful other than helping me find where the gcc headers are included, which is -isystem and -fmacro-prefix-map.
I can’t really do any C++ development right now so any help would be appreciated. Thanks!
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = {nixpkgs, ...}: let
pkgsLinux = import nixpkgs { system = "x86_64-linux"; };
in {
devShells."x86_64-linux".default = pkgsLinux.mkShell.override { stdenv = pkgsLinux.llvmPackages_19.stdenv; } {
system = "x86_64-linux";
packages = with pkgsLinux; [
cmake
];
};
};
}
But when I do it without the funny envvars it’s unable to find stdlib:
dotuncle@kagerou:~/projects/lox/build/ > make
[ 16%] Building CXX object CMakeFiles/lox.dir/src/main.cpp.o
In file included from /home/dotuncle/projects/lox/src/main.cpp:11:
In file included from /home/dotuncle/projects/lox/src/interpreter/Parser.hpp:1:
In file included from /home/dotuncle/projects/lox/src/interpreter/Stmt.hpp:6:
/home/dotuncle/projects/lox/src/interpreter/Expr.hpp:31:8: error: no template named 'unique_ptr' in namespace 'std'
31 | std::unique_ptr<Expr> value;
| ~~~~~^
/home/dotuncle/projects/lox/src/interpreter/Expr.hpp:32:28: error: no template named 'unique_ptr' in namespace 'std'
32 | Assign(Token &name, std::unique_ptr<Expr> &value) : name { name }, value { std::move(value) } {};
| ~~~~~^
/home/dotuncle/projects/lox/src/interpreter/Expr.hpp:40:8: error: no template named 'unique_ptr' in namespace 'std'
40 | std::unique_ptr<Expr> expr;
| ~~~~~^
/home/dotuncle/projects/lox/src/interpreter/Expr.hpp:41:17: error: no template named 'unique_ptr' in namespace 'std'
41 | Grouping(std::unique_ptr<Expr> &expr) : expr { std::move(expr) } {};
| ~~~~~^
...