Why do I need to compile DateTime in boost if I don't use to_string or from_string?

When compiling a Visual Studio 2005 project that references mixed C ++ managed / unmanaged code, I get the following error:

1> LINK: fatal error LNK1104: cannot open file 'libboost_date_time-vc80-mt-1_42.lib'

I followed the Getting Started Guide . The relevance of this fragment:

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

I did a global search for "to_string" and "from_string". There are no occurrences in the code of these DateTime methods.

The documentation for the DateTime library itself has this snippet:

"The library has several functions that require the creation of a library file (mainly the functions to_string, from_string). Most users of the library can effectively use the library WITHOUT building the library, but just include the required ones. If the library is needed, the Jamfile in the build directory will create a" static "library (libboost_date_time ) and a "dynamic / shared" library (boost_date_time) that contains these functions. "

How do I solve this problem? A simple solution is to build a library or use the Windows binary installer from BoostPro, however it bothers me that a compiled library is required when, according to the documentation, I’m not in the situation that requires it.

Another question is that the DateTime documentation seems to indicate that its "mainly to_string, from_string" "can my code possibly reference some other function that would require creating a library file? Who Does anyone know what other functions are included? Are there functions that themselves wrap or call to_string or from_string?

The only thing I use:

#include <boost/date_time/gregorian/gregorian.hpp> 
+6
c ++ boost datetime visual-studio-2005
source share
5 answers

The project compiles and the links are cleared after resolving the following problems:

I defined BOOST_LIB_DIAGNOSTIC - to find out what diagnostic result I can get from the auto-link. Not too informative:

1> Link to the lib file: libboost_date_time-vc80-mt-1_42.lib
1> LINK: fatal error LNK1104: cannot open file 'libboost_date_time-vc80-mt-1_42.lib'

Then I defined BOOST_ALL_NO_LIB = 1 - disables all automatic links. The project is now compiled and linked cleanly.

Boost headers use a pragma to compile signatures when looking for the lib file. Although the date_time library does not do this, the other headers inside boost depend on do.

+3
source share

Just add:

 #define BOOST_DATE_TIME_NO_LIB 

before including boost headers in your code, for example:

 #define BOOST_DATE_TIME_NO_LIB #include <boost/interprocess/shared_memory_object.hpp> #include <boost/interprocess/mapped_region.hpp> .... .... 

I hope this helps, in my case it works.

+9
source share

in my case, this error only occurs on the msvc linker. when compiling with clang or gcc there are no problems at all. By adding

 #define BOOST_DATE_TIME_NO_LIB 

or

 #define BOOST_ALL_NO_LIB 

in the header file, the error has disappeared.

+2
source share

boost comes with a bcp tool that you can use to extract exactly the subset you need. take a look, it seems that you find it useful.

+1
source share

Perhaps you include the "wrong" header, which starts the compiler to communicate with lib, even if you do not need it. Find the #pragma (lib, ...) comment in the boost headers to find out if this is the case.

0
source share

All Articles