To help us debug your issue please explain:
According Conan code, to detect the default compiler, if CC or CXX are configured and there is a valid compiler named there, then it will be used as the default one.
However, when we are running cmake-cmake, CXX is configured by CMake, and it could be valuated as /usr/bin/c++ and Conan will not be able to detect the correct compiler.
I see two possibilities in this case:
_get_default_compiler to detect the correct compiler.NOTE: This situation only affects the scenario where cmake-conan is used AND there is no default profile.
For this example we will need to use cmake-conan, because CMake has a custom CXX.
# CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(MyHello CXX)
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.13/conan.cmake" "${CMAKE_CURRENT_BINARY_DIR}/conan.cmake")
message(STATUS "CXX: $ENV{CXX}")
include(${CMAKE_CURRENT_BINARY_DIR}/conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt BASIC_SETUP)
add_library(hello hello.cpp)
At this point we dont care about conanfile.txt or hello.cpp.
docker run -ti -v ${PWD}:/home/conan/project conanio/gcc72
mkdir build && cd build
cmake ..
The output shall be:
-- The CXX compiler identification is GNU 7.2.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Downloading conan.cmake from https://github.com/conan-io/cmake-conan
-- Conan: Automatic detection of conan settings from cmake
-- Conan: Settings= -s;build_type=Debug;-s;compiler=gcc;-s;compiler.version=7;-s;compiler.libcxx=libstdc++11
-- Conan executing: conan install /home/conan/project/conanfile.txt -s build_type=Debug -s compiler=gcc -s compiler.version=7 -s compiler.libcxx=libstdc++11 -g=cmake
-- WARN: Remotes registry file missing, creating default one in /home/conan/.conan/registry.json
Auto detecting your dev setup to initialize the default profile (/home/conan/.conan/profiles/default)
CC and CXX: None, /usr/bin/c++
ERROR: Not able to automatically detect '/usr/bin/c++' version
ERROR: Unable to find a working compiler
Default settings
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
build_type=Release
* You can change them in /home/conan/.conan/profiles/default
Or override with -s compiler='other' -s ...s*
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=7
os=Linux
os_build=Linux
[options]
[build_requires]
[env]
As you can see, CXX was detected by Conan, because CMake found /usr/bin/c++ as a valid C++ compiler. But Conan is not able understand who is c++.
Conan Version: 1.11.2
Related Issue: https://github.com/conan-io/conan-docker-tools/issues/95
The variable is already defined:
CC and CXX: None, /usr/bin/c++
So the problem is that the auto-detect doesn't understand c++:
if "gcc" in command:
gcc = _gcc_compiler(output, command)
So, yes, it could make sense to fix the auto detect of c++ => g++ (gcc)
The variable is already defined:
Yes, it's defined by CMake. You could check by message(STATUS "CXX: $ENV{CXX}")
please assign this one to me, I am working on proper compiler detection code as part of clang-cl support
Hi @memsharded am I right in assuming that this is an example of the same problem?
If so, +1 to being able to deduce version from c++ --version. That CI run is an example of compiler-agnostic test script. If I have to call conan profile update with the compiler and compiler version, it will mean extra per-job settings which are basically duplicates of the information that can more reliably be gleaned from CC and CXX. Does that make sense?
Thanks, John
Hi @johnmcfarlane
I have just assigned this issue to @SSE4 so he can have a look, hopefully propose a fix for it.
@SSE4 this could be independent of clang-cl, just a check of the compiler defined when it is defined as env-var in CC, CXX.
I am concerned that this could be breaking for users that have in their environment the env-vars defined but do not rely on them (e.g. in Windows, the Visual Studio compiler will have priority, but could be that CC, CXX env vars might be different to what people expect in their default profile)
@lasote do you think this could be breaking behavior in some way?
I think this could be consider it a bug. Also, we always recommend to not trust the autodetected default profile. If the env vars are there, Conan should try to detect the compiler with "c++" also. I vote for improving the detection. And if someone report a breaking behavior we can, as usual, analyze if it is legit or not.
https://github.com/conan-io/conan/pull/5740 was merged, but this doesn't really fix this issue, as it is for CONAN_V2_MODE only. Adding c++ in the old detection might still be worth fixing.
change was reverted, need to re-open for a while
Hi @SSE4 @memsharded , should this issue be reopened since it has been reverted from 1.29 release in the end? Any plans to fix it properly in the near future?
Most helpful comment
I think this could be consider it a bug. Also, we always recommend to not trust the autodetected default profile. If the env vars are there, Conan should try to detect the compiler with "c++" also. I vote for improving the detection. And if someone report a breaking behavior we can, as usual, analyze if it is legit or not.