rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Bindgen doesn't support environment variables like `CC`

Open LoganDark opened this issue 5 years ago • 2 comments

When bindgen says:

error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

I thought I could specify an environment variable CC=/usr/bin/cc or CC_PATH=/usr/bin/cc, but I couldn't. I have to specify a PATH that includes it.

When cross compiling OpenSSL, I specify these environment variables:

CC="x86_64-linux-musl-gcc -fPIE -pie"
CXX="x86_64-linux-musl-g++"
AS="x86_64-linux-musl-as"
AR="x86_64-linux-musl-gcc-ar"
NM="x86_64-linux-musl-gcc-nm"
RANLIB="x86_64-linux-musl-gcc-ranlib"
LD="x86_64-linux-musl-ld"
STRIP="x86_64-linux-musl-strip"

This isn't for cross compilation, and I know that bindgen doesn't use all of these utilities, but it would be nice if bindgen supported these same environment variables.

LoganDark avatar Jul 27 '20 00:07 LoganDark

Can you clarify where does that error come from? Bindgen doesn't link anything for you so I suspect the issue is somewhere else.

emilio avatar Jul 27 '20 10:07 emilio

I have similar problem with CXX variable. With LTS linux distro default compiler doesn't support c++17, so it can not parse something like this:

#include <optional>

default g++ reports

optional not found

So to compile my C++ library I use other compiler with c++17 support like this:

export CC=/usr/local/bin/gcc 
export CXX=/usr/local/bin/g++ 
cmake ... && ninja

But when I want generate Rust binding for my C++ library, bindgen reports that it can not find optional. It would be nice, if bindgen detect existence of CC and CXX variables and call $CXX -v -x c++ -E - to get path to system includes from it.

Dushistov avatar Mar 24 '22 11:03 Dushistov

Should this actually be supported by bindgen and not clang?

pvdrz avatar Sep 21 '22 20:09 pvdrz

Inclined to close this issue because I don't have access to the original environment and I don't remember the reproduction steps.

LoganDark avatar Sep 21 '22 20:09 LoganDark

I'm going to close it then. I think it should be possible to call $CXX -v -x c++ -E - from a build script and inject those into clang using Builder::clang_args but I might be wrong.

Feel free to reopen it if you found this issue again.

pvdrz avatar Sep 21 '22 21:09 pvdrz