3

I am using several Boost libraries in my C++ project. The libraries are acquired through NuGet packages, e.g. the Boost Thread library boost_thread.

Compiling and linking works without any changes to the project properties. But debugging and running the application fails due to missing DLLs in the output directory.

One solution is to use the post build step copying the required DLLs. This is described at other places, e.g. how to make visual studio copy dll to output directory?.

This is an example for the required copy command in the Debug configuration:

xcopy /F /Y "$(SolutionDir)\packages\boost_regex-vc100.1.58.0.0\lib\native\address-model-32\lib\boost_regex-vc100-mt-gd-1_58.dll" "$(OutDir)"

The Project is Visual Studio 2010 project. But the IDE actually used is Visual Studio 2013.

But is there a better way to achieve this?

Community
  • 1
  • 1
Christian
  • 1,017
  • 3
  • 14
  • 30

1 Answers1

1

I used MSBuild's copy task for this exact purpose:

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
  <BoostRT>-gd</BoostRT>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release' Or '$(Configuration)'=='Release_withPDB'">
  <BoostRT></BoostRT>
</PropertyGroup>
<ItemGroup>
<BoostDlls Include="..\packages\boost_log-vc120.1.59.0.0\lib\native\address-model-$(PlatformArchitecture)\lib\boost_log-vc120-mt$(BoostRT)-1_59.dll;
  ..\packages\boost_thread-vc120.1.59.0.0\lib\native\address-model-$(PlatformArchitecture)\lib\boost_thread-vc120-mt$(BoostRT)-1_59.dll;
  ..\packages\boost_system-vc120.1.59.0.0\lib\native\address-model-$(PlatformArchitecture)\lib\boost_system-vc120-mt$(BoostRT)-1_59.dll;
  ..\packages\boost_chrono-vc120.1.59.0.0\lib\native\address-model-$(PlatformArchitecture)\lib\boost_chrono-vc120-mt$(BoostRT)-1_59.dll;
  ..\packages\boost_date_time-vc120.1.59.0.0\lib\native\address-model-$(PlatformArchitecture)\lib\boost_date_time-vc120-mt$(BoostRT)-1_59.dll;
  ..\packages\boost_filesystem-vc120.1.59.0.0\lib\native\address-model-$(PlatformArchitecture)\lib\boost_filesystem-vc120-mt$(BoostRT)-1_59.dll" />
</ItemGroup>
<Target Name="CopyFiles" AfterTargets="Build">
  <Copy SourceFiles="@(BoostDlls)" DestinationFolder="$(OutDir)" />
</Target>

Hardcoding the boost lib version (1.59) is not awesome but other than that it works well.

  • Thanks for sharing your idea. IMHO copying using an xcopy command or an MSBuild task is not much different. You already mentioned the main drawback to hard-code the versions and names is required. I was searching for a way that the information is propagated automatically from nuget. – Christian Mar 19 '16 at 19:28