question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[question (bug?)] How to use Conan center packages in a multi-config environment (Visual Studio)

See original GitHub issue

Minimal example: https://github.com/Adnn/issue_conan-11885

What we are trying

  • Conan 1.51.1
  • Windows 10
  • CMake 3.23.2
  • Visual Studio 2019

We are using the modern CMake generators, , in our conan/conanfile.py:

generators = "CMakeDeps", "CMakeToolchain"

We are following the instruction from CMakeToolchain to configure a multiconfig build environment. This results in the following commands:

conan install conan/
conan install conan/ -s build_type=Debug

conan build conan/
# This next one fails, because the debug build of the upstream lib is found first.
cd build && cmake --build . --config Release

The issue

We would expect it to configure the VS target to link against the Debug (resp. Release) package of the library in the Debug (resp. Release) configuration.

Yet, we observe that both IDE configurations actually have both path (to both Debug and Release packages) configured under Linker > Input > Additional Dependencies.

e.g. with spdlog:

image

This leads to the first path always being picked up, only allowing on configuration to successfully link (because of the _ITERATOR_DEBUG_LEVEL system of MSVC runtime).

The questions

  • Can we fix our use of Conan to actually get a working multi-config VS solution?
  • Is this a bug in Conan/the packages recipe? (We tried a few different recipes from Conan center, and most of them had the same problem).

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
memshardedcommented, Aug 16, 2022

I have been made it work with Conan 1.50 (note that 1.51.1 has some issues that are still pending to be fixed in patch release in 1.51.3 soon in CMakeDeps), with:

conan install conan
conan install conan -s build_type=Debug
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=build\generators\conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -G "Visual Studio 16"
# Open Visual Studio 16 and build and run release and debug
0reactions
memshardedcommented, Sep 13, 2022

Hi @johan-boule

Yes, those files have been already removed in 2.0, and the flow for conan build will be clean, working fine for multi-config too. This seems challenging to solve at this moment in 1.X, so I’d recommend giving a try to the beta and making sure things work fine correctly there (the new conan new cmake_lib -d name=hello -d version=1.0 can help for quick testing)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building for multiple configurations: Release, Debug, Static ...
In this example, we will retrieve the CMake Conan package from a Conan repository with packages compatible with Conan 2.0. To run this...
Read more >
Conan Documentation - Conan Docs
Conan is a software package manager which is intended for C and C++ developers. Conan is universal and portable. It works in all...
Read more >
Conan Documentation - Conan Docs
Conan is a dependency and package manager for C and C++ languages. It is free and open-source, works in all platforms ( Windows,...
Read more >
How to create and reuse packages based on Visual Studio
cpp file contains an #ifdef _DEBUG to switch between debug and release message. In the repository, there is already a conanfile.py recipe: from...
Read more >
conan Documentation - Conan Docs
such as Visual Studio 14, 15, Linux GCC 4.9 and Apple Clang 3.5. . . Conan will throw an error if the binary...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found