conan-io / conan-vs-extension

Conan Extension for Visual Studio
https://marketplace.visualstudio.com/items?itemName=conan-io.conan-vs-extension
MIT License
59 stars 34 forks source link

Static linking inside solution #232

Closed gitandeee closed 1 month ago

gitandeee commented 1 month ago

Hi,

I can not figure out how to solve the following linking configuration. I have a project setup, where an executable links a static library (similar to this example: https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-static-library-cpp?view=msvc-170). The static lib uses the conan extension and loads a dependency (say fmt). The conanfile.py is saved in the correct directory. If I reference this static library inside my executable and compile a linking issue appears, which states that the 3rd party library (fmt) can not be found.

Is there a canonical way of propagating dependencies or is there a configuration step I miss?

Thank you in advance!

gitandeee commented 1 month ago

Hi, I have figured it out. It is necessary to include the conan generated conandeps.props inside the conan directory into the executable properties. This means, it is necessary to include the line

<Import Project="[path to static lib]\conan\conandeps.props" />

into the *.vcxproj of the executable which links the static library, e.g. for the Debug configuration:

  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
      Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
      Label="LocalAppDataPlatform" />
    <Import Project="[path to static lib]\conan\conandeps.props" />
  </ImportGroup>

Best wishes, gitandeee

memsharded commented 1 month ago

Hi @gitandeee

into the *.vcxproj of the executable which links the static library, e.g. for the Debug configuration:

I am not fully sure how VS works in this regard, but if those are subprojects, and they are correctly configured, I also had expected that the properties of the static library propagate to the executable, transitively, without needing to explicitly add the conandeps.props to the executable too.

If you have a reproducible project that you can share, maybe I could try to have a look.