conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.27k stars 981 forks source link

[bug] Profile's compiler.cppstd not respected when installing package #17286

Closed pierricgimmig closed 1 week ago

pierricgimmig commented 1 week ago

Describe the bug

I'm trying to install the abseil package, I'm hoping that my default profile's compiler.cppstd=17 will be respected, but it's not.

Running conan install . -of build --build=missing

gives me:

======== Computing necessary packages ========
abseil/20240116.2: Main binary package 'dee9f7f985eb1c20e3c41afaa8c35e2a34b5ae0b' missing
abseil/20240116.2: Checking 3 compatible configurations
abseil/20240116.2: Found compatible package '9bdee485ef71c14ac5f8a657202632bdb8b4482b': compiler.cppstd=14
Requirements
    abseil/20240116.2#54f81a20ccd26a6558e18d57059847e2:9bdee485ef71c14ac5f8a657202632bdb8b4482b#90b35a9d741f2b46ef5bd2f5ce7516f2 - Cache

It seems that an abseil package with compiler.cppstd=14 is chosen. I would have expected abseil to compile from source using my specified compiler.cppstd=17 instead, is this expected? I need cpp 17 so that abseil compiles with std::string_view support. The code below won't compile without it. Thanks for your help.

Windows 11, conan 2.8.1

C:\Users\pierr\git\conan_abseil (main)
λ conan profile show
Host profile:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=193
os=Windows

Build profile:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=193
os=Windows

How to reproduce it

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(compressor CXX)

# Set C++17 standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(absl REQUIRED)

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} abseil::abseil)

conanfile.txt

[requires]
abseil/20240116.2

[generators]
CMakeDeps
CMakeToolchain

main.cpp

#include <iostream>
#include <string.h>
#include <absl/strings/str_cat.h>

void main()
{
    std::string_view blah = "blah";
    std::string message = absl::StrCat("Hello, Abseil ", blah, "!");
    std::cout << message << std::endl;
}

then run conan install . -of build --build=missing

memsharded commented 1 week ago

Hi @pierricgimmig

Thanks for your feedback.

This is not a bug, but intended. The default binary compatibility compatibility.py implements binary compatibility across different compiler.cppstd values, so if there is no existing binary for cppstd=17 it can fallback to an existing cppstd=14.

If you want to force the build of the cppstd=17 it is possible:

Please try that and let us know.

pierricgimmig commented 1 week ago

Hi @memsharded , thanks for the detailed answer. Running with build="abseil/*" does indeed fix the issue, thank you!

memsharded commented 1 week ago

Nice, happy to help.

I am closing the ticket then as solved, but feel free to re-open or create new tickets if there are any further question or issues. Thanks for the feedback!