2

I have a Console Project LinkExample that contains a main.cpp.

#include <Library/Logger.hpp>
int main()
{
    WriteSomething();
    return 0;
}

The LinkExample links a static Library Project named Library. Library.Lib is linked correctly.

Library contains a Logger.hpp

#pragma once
void WriteSomething();

Logger.cpp

#include <boost/log/trivial.hpp>
#include <Library/Logger.hpp>

void WriteSomething()
{
    BOOST_LOG_TRIVIAL(trace) << "Trace";
}

The NuGet Packages are:

  <?xml version="1.0" encoding="utf-8"?>
  <packages>
    <package id="boost" version="1.63.0.0" targetFramework="native" />
    <package id="boost_log-vc140" version="1.63.0.0" targetFramework="native" />
  </packages>

LinkExample does not build and shows the error LNK1104 for file libboost_log-vc140-mt-gd-1_63.lib.

When linking statically I would want this library to be baked into Library, why does this not happen and how can I fix that?

I am aware that I could add packages to LinkExample but that is not a long term solution.

Adding packages until the solution runs would include these packages.

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="boost" version="1.63.0.0" targetFramework="native" />
  <package id="boost_date_time-vc140" version="1.63.0.0" targetFramework="native" />
  <package id="boost_filesystem-vc140" version="1.63.0.0" targetFramework="native" />
  <package id="boost_log-vc140" version="1.63.0.0" targetFramework="native" />
  <package id="boost_system-vc140" version="1.63.0.0" targetFramework="native" />
  <package id="boost_thread-vc140" version="1.63.0.0" targetFramework="native" />
</packages>

In a larger Project things started falling apart with this approach after switching boost to dynamic linking.

How do I get rid of my root problem that the lib files are linked by my customer library?

Note that the "Link Library Dependencies" setting does nothing here, using this setting would require a project setup that is incompatible with NuGet.

Johannes
  • 6,490
  • 10
  • 59
  • 108
  • The project needs that NuGet Package file in the library. – Jeroen Heier Feb 05 '17 at 08:11
  • The packages are connected by NuGet and the lib files are connected by the extension targets that come with the packages. Adding the ´LinkExample´ is like the Customer. The Customer should not know about anything statically linked. – Johannes Feb 06 '17 at 06:32

1 Answers1

3

This is the default behavior of Visual studio. We could not use the NuGet Packages as dependencies directly in the LinkExample project, which provide by the linked customer library. The Visual studio only load the files of static Library Project when we build the LinkExample project, those dependencies of static Library Project would not be loaded. So I agree with Jeroen Heier, if you want to use those packages to LinkExample project, you need to add packages to LinkExample.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    So I read up further on the topic and I had a misconception about static libraries. What I read is that only dynamic libraries and executeables are final linker stages. The behavior I want is coupled to the final linker stage - so I can fix this by making `Library` into a dll. – Johannes Feb 06 '17 at 18:42