conan-io/conan

Failure to detect gcc when gcc is compiled with --with-gcc-major-version-only

barcharcraz opened this issue · 4 comments

Opensuse has been shipping gccs that output just the major number for gcc -dumpversion for many years. In gcc7 there is a switch --with-gcc-major-version-only that triggers this behavior (and suse's gcc7 packages use it). Because of the regex used on line 28 of detect.py conan fails to detect gcc in these cases.

Sorry didn't get the proper solution. How should gcc --version be invoked to get the minor too? The minor is also needed.

In any case, not a critical issue, if detect fails to detect the default gcc, it can be easily configured editing conan.conf

Hi @barcharcraz, we could include this for next release, but I have been googling for a solution, and still not clear. Would it work if we did gcc --version and parse the output, instead of gcc -dumpversion?

SSE4 commented

@memsharded I use the following code in my scripts to detect GCC version

COMPILER_MAJOR=$(touch test.c && gcc -E -dM test.c  | grep -o '__GNUC__ [[:digit:]]' | cut -d' ' -f2)
COMPILER_MINOR=$(touch test.c && gcc -E -dM test.c  | grep -o '__GNUC_MINOR__ [[:digit:]]' | cut -d' ' -f2)

and for clang

COMPILER_MAJOR=$(touch test.c && clang -E -dM test.c  | grep -o '__clang_major__ [[:digit:]]' | cut -d' ' -f2)
COMPILER_MINOR=$(touch test.c && clang -E -dM test.c  | grep -o '__clang_minor__ [[:digit:]]' | cut -d' ' -f2)

basically idea is to use compiler version macro rather parsing --version output which may be hard to parse in reliable manner.
do you think if it makes sense to add something like that to conan detection?

Sorry for leaving this so long unresolved.
@SSE4 I think implementing that in conan codebase is too much, so far doesn't seem worth to deserve the effort.
@barcharcraz The regex has improved, now able to use only the major (and #2084 introduces support for major-only gcc setting for 5, 6, 7.