-2

I am working with some autogenerated C++ code provided by a vendor. They use the Boost libraries extensively, and as such I also need to use the boost libraries in order to create the appropriate objects to send as inputs to vendor methods. They provide all the Boost header files within a lib folder in the autogenerated code.

I have never used Boost before, but from what I've gathered in the past few days it is for the most part a header only library, which to me means that there are no *.dlls or *.lib files required to use it in my software provided I don't use the listed features that do require a lib file.

The problem I am having is when I try to include "boost\date_time.hpp" when it comes time to build it I get a LNK1104 error "cannot open file libboost_date_time-vc140-mt-gd-1_38.lib". I have noted that on the Boost website it says that some libraries do have optional compiled libraries depending on if certain features are used; for date_time it says the following:

"Boost.DateTime has a binary component that is only needed if you're using its to_string/from_string or serialization features, or if you're targeting Visual C++ 6.x or Borland."

I do not require any of the features that would require a compiled library, and have not referenced any features at all yet in my code, simply added the include. So why is it demanding this file? Also, how does it even know what file to demand? Is there a sneaky #pragma hidden in one of the header files? I started to look but there were too many paths to go down.

The vendor does supply a compiled dll and lib file for Boost.DateTime, however it is named 'boost_date_time-vc140-mt-gd-1_38.lib', the file the compiler is looking for has 'lib' prefixed to the front. If it does require it, then how can I direct the linker to the correct file? I know I can change the name of the file to what the linker is looking for (the linker has the path to the folder containing the file already, it is nothing to do with that) but as this code comes from the vendor code generation software it will frequently revert back to the original file name, so that would not be an optimal solution.

As always, thank you for any help you can provide.

Steven Gillies
  • 471
  • 7
  • 18
  • 1
    `Is there a sneaky #pragma hidden in one of the header files?` There is. The `BOOST_ALL_NO_LIB` macro disables this "feature" – tkausl Aug 23 '18 at 15:47
  • You should clean up your question. You start with Boost is header-only (it's not) and later correctly note some libraries have compiled components too. There's no such thing as `data_time`, it's `date_time`. If you don't require Boost features, why are you including `boost/date_time.hpp`? And it doesn't matter if your code doesn't use the compiled component, if the third party code you're using references it, you will need the library. Finally, doesn't this vendor provide instructions on how to use their code? – Praetorian Aug 23 '18 at 15:57
  • πάντα ῥεῖ, the question was not about how to link to a different version of Boost, the version is correct in both the error and the file i'm trying to get it to link to. The problem was that I didnt think it should need a .lib file at all, but if it did where did it get the file name from and how can I change it. You seem to have marked this a duplicate of a question asking how to reference a different version of Boost altogether. – Steven Gillies Aug 23 '18 at 15:59
  • tkausl your answer was the one I was looking for. If you want to post it as an answer I will accept it. I just added the line '#define BOOST_ALL_NO_LIB' before including the boost header file and it has now built successfully. – Steven Gillies Aug 23 '18 at 16:16
  • 2
    @StevenGillies _"If you want to post it as an answer I will accept it."_ They can't unless I (or 5 others) decide to reopen the question (I'll do that now). Anyways next time try to keep your question as narrow and clear as possible. Best provide a [MCVE] demonstrating what didn't work with your code, instead of writing lengthy and confusing prose. – πάντα ῥεῖ Aug 23 '18 at 16:22
  • 1
  • "it is for the most part a header only library" - I wouldn't say that. Many parts of boost are header only, but just as many are not. – Jesper Juhl Aug 23 '18 at 16:48

1 Answers1

0

As tkausl mentioned in the comments there was a #pragma comment in a header file trying to load the lib.

By adding the line '#define BOOST_ALL_NO_LIB' before the '#include "boost\date_time.hpp"' line this solved the problem as the defined Macro tells Boost to not to load the lib file.

Steven Gillies
  • 471
  • 7
  • 18