-
Notifications
You must be signed in to change notification settings - Fork 453
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
Compiler version doesn't include clang or GCC: "cc" "--version" #958
Comments
That may be a good idea, however I'm not sure how it affects msvc and other compilers. |
I am also seeing this on GitHub Actions' Ubuntu 22.04 runner: https://github.com/KDAB/cxx-qt/actions/runs/7986404801/job/21806762461?pr=848#step:14:93 I cannot reproduce the warning locally on Fedora 39. |
I'm seeing this too
|
The standard way to check what version of compiler you have is to analyze the preprocessor definitions defined by the compiler for a trivial program. Simply relying on the output of For instance, CMake looks at preprocessor definitions emitted by the compiler to detect compiler versions. It's usually pretty complex for the more difficult compilers, but this is more reasonable than relying on inspecting the output of Clang:
GCC:
|
Thanks, I will work on a patch once I fixed the make problem. |
Ok so for clang we can use: #define XSTR(x) STR(x)
#define STR(x) #x
#pragma message "COMPILER_VERSION_MAJOR = " XSTR(__clang_major__)
#pragma message "COMPILER_VERSION_MINOR = " XSTR(__clang_minor__)
#pragma message "COMPILER_VERSION_PATCH = " XSTR(__clang_patchlevel__)
#if defined(_MSC_VER)
/* _MSC_VER = VVRR */
# pragma message "SIMULATE_VERSION_MAJOR = " XSTR(_MSC_VER / 100)
# pragma message "SIMULATE_VERSION_MINOR = " XSTR(_MSC_VER % 100)
#endif
#if defined(_MSC_VER)
# pragma message "SIMULATE_ID = MSVC"
#endif on my macOS system, using the homebrew
Using the
Running real
Same output when using
|
For GCC:
For
For clang, clang++ and clang-imposed cc, c++, gcc, g++ , they all give version |
TODO for myself: Also test zig-cc output Would also be great to test different compilers in CI |
Output of
slightly different from |
I don't know Rust and have never seen this repo before, but it's affecting some third-party software I'm using that needs this library. (I am, however, very familiar with C/C++.) Since we're invoking the compiler to begin with, perhaps we could do a little more work to get something more reliable? For example, we could compile and run a small program like this: #ifdef __cplusplus
# include <cstdio>
#else
# include <stdio.h>
#endif
int main() {
/* Always check Clang before __GNUC__ because it defines that too */
#ifdef __clang__
printf("clang | %s\n", __clang_version__);
return 0;
#endif
#ifdef __GNUC_VERSION__
/* Could be TCC or another compiler professing compatibility, so we may need
to do further checks, especially if we're choosing CLI arguments based on
the compiler and version. */
printf(
"GCC | %d.%d.%d\n",
__GNUC_VERSION__ / 10000,
__GNUC_VERSION__ / 100,
__GNUC_VERSION__ % 100
);
return 0;
#endif
#ifdef _MSC_VER
printf("MSVC | %d.%d\n", _MSC_VER / 100, _MSC_VER % 100);
return 0;
#endif
/* Unrecognized compiler */
return 1;
} We could get detailed information from this, such as the width of I've found this list highly useful for compiler detection. There are other lists for detecting OS and host/target architecture. |
Thanks @dargueta I would open a PR for this soon. |
Don't copy and paste that, I just noticed a bug (missing return statements). |
I will probably just use the macro-only and use |
This comment was marked as resolved.
This comment was marked as resolved.
Ok I decided to use the following #ifdef __clang__
# pragma message "clang"
#else
# ifdef __GNUC__
# pragma message "gcc"
# endif
# ifdef _MSC_VER
# pragma message "msvc"
# endif
#endif Tested with clang, apple clang and gcc on macOS, mingw gcc and msvc on windows |
Tested Clang and GCC on Ubuntu 23.10 and it works. Thanks! |
I have this problem in our CI Containers. They are based on Ubuntu 20.04 and I will never be able to change that for reasons irrelevant to this issue so I would appreciate if this gets fixed for older versions of ubuntu/debian too. This is the output from cc --version. |
For everyone subscribing, #1000 should fix this and once it is merged, I will cut a new release. |
@NobodyXu do you have a estimate for the new release? Thank you! |
Waiting for #1015 to merge |
Update non-bootstrap `cc` dependency to fix compile family detection warning `x.py check compiler/rustc_llvm` **Before:** (rust-lang/cc-rs#958) <pre> Checking stage0 compiler artifacts {rustc_llvm} (x86_64-unknown-linux-gnu) Compiling cc v1.0.90 Compiling libc v0.2.153 Compiling rustc_llvm v0.0.0 <b>warning: rustc_llvm@0.0.0: Compiler version doesn't include clang or GCC: "c++" "--version"</b> Finished `release` profile [optimized] target(s) in 28.09s </pre> **After:** <pre> Checking stage0 compiler artifacts {rustc_llvm} (x86_64-unknown-linux-gnu) Compiling libc v0.2.153 Compiling cc v1.0.92 Compiling rustc_llvm v0.0.0 Finished `release` profile [optimized] target(s) in 29.06s </pre>
Update non-bootstrap `cc` dependency to fix compile family detection warning `x.py check compiler/rustc_llvm` **Before:** (rust-lang/cc-rs#958) <pre> Checking stage0 compiler artifacts {rustc_llvm} (x86_64-unknown-linux-gnu) Compiling cc v1.0.90 Compiling libc v0.2.153 Compiling rustc_llvm v0.0.0 <b>warning: rustc_llvm@0.0.0: Compiler version doesn't include clang or GCC: "c++" "--version"</b> Finished `release` profile [optimized] target(s) in 28.09s </pre> **After:** <pre> Checking stage0 compiler artifacts {rustc_llvm} (x86_64-unknown-linux-gnu) Compiling libc v0.2.153 Compiling cc v1.0.92 Compiling rustc_llvm v0.0.0 Finished `release` profile [optimized] target(s) in 29.06s </pre>
Under Ubuntu 23.10 (gcc 13), older cc crate versions would complain that the compiler could not be identified. See rust-lang/cc-rs#958
Under Ubuntu 23.10 (gcc 13), older cc crate versions would complain that the compiler could not be identified. See rust-lang/cc-rs#958
On Debian Sid:
Output of
cc --version
, which is different fromgcc --version
:Output of
cc -v
, which is the same asgcc -v
:So it's may be better to use
-v
to check the compiler type?The text was updated successfully, but these errors were encountered: