Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting linkage type for C++ library installed via Nuget

Tags:

This answer mentions the following method to link to the static version of a C++ library [in this case, "freeglut"] installed via Nuget:

Project->Properties->Configuration Properties->Referenced Packages->freeglut->Linkage (select static) 

With Visual Studio 2015 I can't find "Referenced Packages". The only explicit reference to Nuget packages that I have is the packages.config xml file. If I go to the "Manage Nuget packages" section of the project I can install or un-install but I can't find any detail of the package.

I have searched msdn for documentation but all the pages are devoted to the creation of a package, while I need to espress the way to consume such a package. The package in question (Boost Unit Test Framework) can be used header-only, with static or with dynamic linkage and I would like to know where I can decide it.

Maybe I am getting old, but Nuget is a bit too magic for me...

UPDATE

This is what I am seeing - you can see that there are Nuget packages installed, in particular boost, but that under the Configuration properties there is no link to "Referenced packages": screenshot of Nuget installed packages and of the Configuration Properties without a link to "Referenced Packages

For completeness, the version of VS 2015 Enterprise is:

14.0.25431.01 Update 3

and I have checked that when I installed the Boost Test Package I got both the static (.lib) and dynamic (.dll) linkage versions, since the files for my VS version are present in the packages folder.

like image 865
Francesco Avatar asked Aug 20 '17 17:08

Francesco


2 Answers

With Visual Studio 2015 I can't find "Referenced Packages".

It depends on whether you have installed freeglut package into your project. If you create a C++ project without any NuGet package installed, you could not find the "Referenced Packages":

enter image description here

After installed the nuget package "freeglut", the "Referenced Packages" and "Project Master Settings" would add to the Configuration Properties:

enter image description here

Update for Boost Package: You should install the package freeglut to check the "Referenced Packages" and "Project Master Settings". Since you noticed the different behavior between the package freeglutand Boost, I would like provide more about Native NuGet packages. After installed the freeglut and Boost in to your project, you can find the freeglut.targets and boost.targets in the packages folder(..\packages\freeglut.2.8.1.15\build\native & packages\boost.1.64.0.0\build\native), open them with notepad or VS, you will noticed that:

In freeglut.targets:

<PropertyGroup Label="Debug and static and RuntimeLibraryNull" Condition="( $(Configuration.ToLower().IndexOf('debug')) &gt; -1 ) And '$(Linkage-freeglut.ToLower())' == 'static' And ('$(RuntimeLibrary)' == '')">
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
 </PropertyGroup>
 <PropertyGroup Label="Release and static and RuntimeLibraryNull" Condition="( $(Configuration.ToLower().IndexOf('debug')) == -1 ) And '$(Linkage-freeglut.ToLower())' == 'static' And ('$(RuntimeLibrary)' == '')">
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</PropertyGroup>
<PropertyGroup Label="Debug and ltcg and RuntimeLibraryNull" Condition="( $(Configuration.ToLower().IndexOf('debug')) &gt; -1 ) And '$(Linkage-freeglut.ToLower())' == 'ltcg' And ('$(RuntimeLibrary)' == '')">
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</PropertyGroup>
<PropertyGroup Label="Release and ltcg and RuntimeLibraryNull" Condition="( $(Configuration.ToLower().IndexOf('debug')) == -1 ) And '$(Linkage-freeglut.ToLower())' == 'ltcg' And ('$(RuntimeLibrary)' == '')">
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</PropertyGroup>

This will add the options "Referenced Packages" and "Project Master Settings" via PropertyGroup in to the C++ properties.

But in the boost.targets file, only:

   <ItemDefinitionGroup>
    <ClCompile>
      <PreprocessorDefinitions>;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\..\lib\native\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ClCompile>
  </ItemDefinitionGroup>

So whether the "Referenced Packages" and "Project Master Settings" will be added is based on the .targets file in the package`s folder.

If I go to the "Manage Nuget packages" section of the project I can install or un-install but I can't find any detail of the package.

On the right of the "Manage Nuget packages" section of the project, you can notice some more detail Description:

enter image description here

I have searched msdn for documentation but all the pages are devoted to the creation of a package, while I need to espress the way to consume such a package.

You can refer to the document Consume Packages for how to consume a package.

The package in question (Boost Unit Test Framework) can be used header-only, with static or with dynamic linkage and I would like to know where I can decide it.

You can decide it on the Project->Properties->Configuration Properties->Referenced Packages->freeglut:

enter image description here

like image 176
Leo Liu-MSFT Avatar answered Sep 29 '22 20:09

Leo Liu-MSFT


Boost is using auto-linking. It means, the Boost source code decides which library (file) to use depending on build environment and configuration.

Update Here's the process

  1. You add the Boost headers only NuGet package to your project.
  2. Depending on what are you using and build configuration, Boost may require additional libraries (lib files). In this case, you will receive a compilation/linking error.
  3. Depending on the compilation/linking error, you add to your project additional NuGet packages with precompiled Boost libraries from here

I agree, the process is not obvious. To improve it, Boost should finalize their modularization first. I mean, when Boost libraries (headers and binaries) can be shipped separately.

like image 35
Sergey Shandar Avatar answered Sep 29 '22 22:09

Sergey Shandar