Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix-shell environment does not work well with clangd #3276

Closed
thongpv87 opened this issue Dec 18, 2019 · 5 comments
Closed

nix-shell environment does not work well with clangd #3276

thongpv87 opened this issue Dec 18, 2019 · 5 comments

Comments

@thongpv87
Copy link

thongpv87 commented Dec 18, 2019

I have a cmake project with following nix environment:

with (import <nixpkgs> {});
clangStdenv.mkDerivation {
  name = "myapp";
  version = "dev-0.1";
  src = ./.;
  nativeBuildInputs = [ cmake git pkgconfig clang_9 ];
  buildInputs = [
    libpcap
    gtest
    boost169
    tbb
    protobuf
    cppzmq
    czmq
  ];
}

The app is built successfully, but clangd can not find the symbol. I thing the problem is CPATH or C_INCLUDE_PATH, CPLUS_INCLUDE_PATH is not set (https://clang.llvm.org/docs/CommandGuide/clang.html).

My temporary solution is:

$ nix-shell
$ touch main.cpp && clang++ -c main.cpp -v
 ........................
#include "..." search starts here:
#include <...> search starts here:
 /nix/store/r60zj33ql368zhlmbmkb09708cx2x62s-compiler-rt-9.0.0-dev/include
 /nix/store/95gcjjxrafz14lcm1qlr0c22cllq0z0g-compiler-rt-7.1.0-dev/include
 /nix/store/dwg4f08dfjh1bp01dl9lab37k4izl3zf-libpcap-1.9.1/include
 /nix/store/3vqq9cycszr92rra71n66hhp7nd1q3yq-gtest-1.10.0-dev/include
 /nix/store/3dzmwvwwmg9l2qhz797fwpvzq5qy8n98-boost-1.69.0-dev/include
 /nix/store/wm1nb0fi7f8zskaa9hmp318hvsqh5brj-tbb-2019_U9/include
 /nix/store/z7b936n47c6sfpjim4fkahgh5q8vwplm-protobuf-3.7.1/include
 /nix/store/8kzhxcvpp55ci4k5gv2b9gssqw6y73n4-cppzmq-4.4.1/include
 /nix/store/rfxwlichcbakhhz17vb8vjlqk5p2gkrw-czmq-4.2.0/include
 /nix/store/z3ly1ixkz3zk6nmhwyrirjq7y5mb5gmy-zeromq-4.3.2/include
 /nix/store/vgn1sxcj5ma9m5bhjps1q9jx3q2ab27c-gcc-8.3.0/include/c++/8.3.0
 /nix/store/vgn1sxcj5ma9m5bhjps1q9jx3q2ab27c-gcc-8.3.0/include/c++/8.3.0/x86_64-unknown-linux-gnu
 /nix/store/86s2mcrbl9i020zdxyv84s8vc49hiwis-clang-wrapper-9.0.0/resource-root/include
 /nix/store/zknwniygdjjhizjw70jdk67fyf4y2bn9-glibc-2.27-dev/include

$ # set the CPATH variable according to include path in * #include<...> starts here * 
$ export CPATH=......
$ clangd&

I thing this should be added to the mkDerivation function

@lheckemann
Copy link
Member

Does this work if you make the set recursive (add rec between mkDerivation and {) and add

CPATH = lib.makeSearchPathOutput "dev" "include" buildInputs;

to the set?

@LnL7
Copy link
Member

LnL7 commented Dec 18, 2019

Unlike clang/clang++ the clangd binary isn't wrapped to make it resolve nix inputs. I currently use compile_fags.txt to make multiple tools aware of them. We might be able to wrap clangd, but that's an issue that belongs in nixpkgs.

@thongpv87
Copy link
Author

@lheckemann It works perfectly. Thank you so much.

@lheckemann
Copy link
Member

Someone please close this, since it's not a nix issue

@lheckemann
Copy link
Member

Related nixpkgs issue: NixOS/nixpkgs#92739

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants