laduke
October 25, 2020, 6:21pm
1
Hello. older related thread here
The other thread has some wrapper work-arounds but at the end also suggests maybe it got improved in nix?
I’m trying to get a basic llvm/cmake nix-shell going. It mostly works, but clang-tidy doesn’t know where stuff is.
[nix-shell:~/src/cpp/hello]$ cat shell.nix
with import <nixpkgs> {};
clangStdenv.mkDerivation {
name = "env";
nativeBuildInputs = [ cmake ];
}
[nix-shell:~/src/cpp/hello]$ $CXX src/Hello.cpp
[nix-shell:~/src/cpp/hello]$ clang-tidy src/Hello.cpp
1 error generated.
Error while processing /Users/travis/src/cpp/hello/src/Hello.cpp.
/Users/travis/src/cpp/hello/src/hello.cpp:1:10: error: 'iostream' file not found [clang-diagnostic-error]
#include <iostream>
^
Found compiler error(s).
I’m new at nix. What approach should I take?
If anyone has a a little llvm hello world shell.nix repo, that’d be cool.
I was getting mixed signals from discourse about whether to make a new thread or bump the old. Sorry if I chose wrong.
1 Like
(I think creating a new thread and linking to the old one is perfectly fine.)
I’m having problems with clang-tidy from nixpkgs too.
This is what I found so far:
The clang-tidy you’re running there is the unwrapped one. If you explicitly add clang-tools
to the nativeBuildInputs
list you get the wrapped one. (Maybe it’s a packaging bug that we add the unwrapped one implicitly. Why would we ever want that?)
With the wrapped clang-tidy
in $PATH
, it’ll find headers like <iostream>
.
The next problem is cang-tidy
barfs on #include <cmath>
!
Searching for the #include <cmath>
issue lead me to Build failure on clang/libc++ 4.0 · Issue #937 · Andersbakken/rtags · GitHub . But so far I’m unable to resolve that. I tried hacks like export NIX_CFLAGS_COMPILE="-isystem ${libcxx}/include/c++/v1 $NIX_CFLAGS_COMPILE"
, but it didn’t work.
1 Like
Relevant post (and its follow up response):
I cannot really formulate the question entirely. I’d like to make better use of the clang tooling in a nix-shell environment where I build stuff using the regular gcc + GNU libstdc++ toolchain and somehow the include paths clash to produce a lot of:
In included file: no member named 'signbit' in the global namespace; did you mean '__signbit'?clang(no_member_suggest)
See: clang-tools: teach about nix's include path · NixOS/nixpkgs@a10ef1a · GitHub
Despite me commenting on this I have never rea…
laduke
October 31, 2020, 6:39pm
5
Thanks! Using clang-tools
is good enough for me for now.