Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need to compile DateTime in boost if I am not using to_string or from_string?

When compiling a Visual Studio 2005 project that references a mix of 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 have followed the Getting Started Guide. Of relevance is this snippet:

"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 have done a global search for "to_string" and "from_string". There are no occurrences in the code of these DateTime methods.

In the documentation for the DateTime library itself, there is this snippet:

"The library has a few functions that require the creation of a library file (mostly to_string, from_string functions). Most library users can make effective use of the library WITHOUT building the library, but simply including the required headers. If the library is needed, the Jamfile in the build directory will produce a "static" library (libboost_date_time) and a "dynamic/shared" library (boost_date_time) that contains these functions."

How would I got about resolving this issue? The easy solution is to build the library or use the Windows binary installer from BoostPro, however it bothers me that the compilred library is being required when according to the documentation I am not in the situation that requires it.

Another question is the DateTime documenation seems to indiciate that its "mostly to_string, from_string)", could my code perhaps be referencing some other function that would require creating the library file? Does anyone know what other functions are included? Are there functions that themselves wrap around or call to_string or from_string?

The only inclusion I am using is:

#include <boost/date_time/gregorian/gregorian.hpp>
like image 497
mindless.panda Avatar asked Mar 02 '10 16:03

mindless.panda


2 Answers

Just add:

#define BOOST_DATE_TIME_NO_LIB

before including the boost headers in your code eg:

#define BOOST_DATE_TIME_NO_LIB

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

....
....

I hope it would help, in my case it works.

like image 117
baha boru Avatar answered Oct 03 '22 03:10

baha boru


Project compiles and links cleanly after the following troubleshooting:

I defined BOOST_LIB_DIAGNOSTIC - to see what diagnostic output I could get from the auto linker. Not too informative:

1>Linking to 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'

I then defined BOOST_ALL_NO_LIB=1 - disables all auto linking. Project now compiles and links cleanly.

Boost headers use pragma to signal compilers when to look for a lib file. While the date_time library does not do this, other headers within boost it depends on do.

like image 20
mindless.panda Avatar answered Oct 03 '22 02:10

mindless.panda