Reputation: 9528
I am using conan to handle dependencies and I have already been able to compile and run the project by running individual steps like source
and build
.
I however want to be able to install and build in a single step, and for that purpose I do:
conan install . -if build -s build_type=Debug --build
In which case for some packages I get:
Compiler version specified in your conan profile: 10.3
Compiler version detected in CMake: 9.3
Please check your conan profile settings (conan profile show
[default|your_profile_name])
P.S. You may set CONAN_DISABLE_CHECK_COMPILER CMake variable in order to
disable this check.
Now I can change the profile settings to match the requested compiler settings, but then other, different, packages start complaining about mismatching compiler versions. i.e. some packages want version 9.3, others version 10.3, others version 9...
Considering the packages dependencies already link with my executable if I just run the build steps individually, I am not sure why I am getting this catch 22 behaviour.
I tried a suggestion in the comments by adding this to my conanfile.py
def configure(self):
# gcc compiler version
defs = {}
if self.settings.compiler == "gcc":
defs["CMAKE_C_COMPILER"] = f"gcc-{self.settings.compiler.version}"
defs["CMAKE_CXX_COMPILER"] = f"g++-{self.settings.compiler.version}"
# configure cmake
cmake = CMake(self)
cmake.configure(defs = defs)
return super().configure()
I get an exception.
Upvotes: 0
Views: 3342
Reputation: 726
If you don't tell CMake about the compiler you want to use, it will try to discover it in the project(...)
call. If they don't match, a check performed by a Conan macro will fail.
Typically, if you want to use a compiler version different from the default you need to inform CMake about it. One of the most common ways to do it using Conan profiles is to add the CC
and CXX
variables to the profile itself.
[settings]
...
compiler=gcc
compiler.version=10.3
...
[env]
CC=/usr/bin/gcc-10
CXX=/usr/bin/g++-10
Conan will add these variables to the environment before calling the build system and most of them (CMake, Autotools,...) will take them into account.
This way, you don't need to modify the conanfile.py
file.
Upvotes: 3