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
Adding Clang to the buildInputs breaks G++/GCC linkage step #29877
Comments
Here is a one-file reproduce.
{ pkgs ? import <nixpkgs> {} }:
pkgs.stdenv.mkDerivation rec {
name = "clang_with_gcc_test";
buildInputs = [ pkgs.clang ];
src = pkgs.writeTextDir "test.cpp" "int main() {}";
buildPhase = ''
g++ test.cpp -o $out
'';
dontInstall = true;
} Steps to reproduce: nix-build clang-gcc.nix |
@LnL7, @Ericson2314 |
Issue described in NixOS/nixpkgs#29877
Issue described in NixOS/nixpkgs#29877
Issue described in NixOS/nixpkgs#29877 Also includes: - more performant Nix build (more cores used) - suppressed builder output to avoid hitting 4 MB log limit on Travis
Offtopic: excuse me for so many references to this issue, since I've falsely put issue number into the commit message. |
@orivej Is there a reason to have 2 wrapped compilers in a build environment? (and use both of them) When including the clang wrapper |
Might be relevant, but @LnL7 made a Long term, @LnL7 and I also talked about having a |
@LnL7 Currently three cases are not supported:
So far there seems to be no need for the second case. The first is just inconvenient (and may be improved by exposing (As an aside, @Ericson2314 Binding the wrapped |
Per request of @orivej I'm mentioning how this issue is affecting my workflow. I use irony and rtags for my C/C++ development. The basic principle of these tools is that they use libclang to process your source code for IDE-like functionality, i.e. autocomplete, jump-to-definition, find refs etc. To process your project, it must be compiled by clang. The problem is that clang doesn't have a standard library in it's search path, so if your project has (as an example) The ideal situation for me is one where I can use both gcc and clang standalone from my regular command line. This was I can compile my projects with gcc and clang, but also use clang as the backend for my dev tools. Right now this is impossible without workarounds. |
I'm in the same pickle. Need to have g++ and clang++ to do C++ developement. |
See: |
That fixes it just partially (I'm on nixpkgs' master)
g++ works correctly and compiles the example. |
@ekmecic writes about this problem and that he has developed some workaround for it... |
I've had this same problem, and I solved it in my toolbench.
|
Interestingly this "works". g++ and clang++ are able to compile and link correctly. Yes, gcc6 version is 32bit only and clang_6 version is 64bit version only. Don't ask me why, I do not understand why one is 32bit and other 64bit, I would expect both to be 32bit versions - pkgsi686Linux... pkgs.pkgsi686Linux.stdenv.mkDerivation rec { |
Can someone confirm this is still an issue? |
I believe it is still an issue. clang brings that flag that breaks gcc (g++: error: unrecognized command line option '-stdlib=libstdc++'; did you mean '-static-libstdc++'?) and clang-unwrapped cannot find system includes (fatal error: 'stdio.h' file not found). |
We don’t need to set -stdlib=libstdc++. This only works on Clang so it is not good to set it globally. In addition, Clang knows to use libstdc++ on Linux by default if no stdlib is set: https://github.com/llvm-mirror/clang/blob/324f918438715b4a0d024af5930628c1674f4fcd/lib/Driver/ToolChains/Linux.cpp#L456 It’s a good policy to just leave off stdlib for now. Fixes NixOS#29877.
@matthewbauer I'd like to try it, but I do not know how to trigger rebuild of clang (as only .sh is changed). Is there any trick how to do it? I'm running NixOs on master. |
Issue description
Clang, when specified as a dependency in
buildInputs
breaks G++ linkage, by introducing unrecognized flags for GNU linker viaNIX_CXXSTDLIB_LINK
environment variable.Steps to reproduce
Create
shell.nix
:Launch shell:
Try to compile test C++ program:
Observe output:
Technical details
Seems that it is a clang's setup hook that exposes that flag:
https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/llvm/4/libc++/setup-hook.sh#L3
So, issue can be workarounded either by removing Clang from
buildInputs
, or adding own hook toshell.nix
:System: ArchLinux:
Nix version: 1.11.15
Nixpkgs version: 18.03pre116475.d757d8142e
Sandboxing enabled: no
P.S.
Thanks to @rasendubi for helping me figure out why it behaves like that!
The text was updated successfully, but these errors were encountered: