
I'm trying to test the date_time functionality of boost and am having some difficulties. I would like to simply get the current local time into a ptime and write it out as an ISO-8601 string. Using Boost 1.29 and g++ 3.2, when I compile the following code I get a number of *linker* errors. Code: #include <boost/date_time/posix_time/posix_time_types.hpp> #include <boost/date_time/posix_time/time_formatters.hpp> int main() { boost::posix_time::ptime pt = boost::posix_time::second_clock::local_time(); std::cout << boost::posix_time::to_iso_extended_string(pt) << std::endl; } That code seems pretty straightforward to me. The linker errors look like the following: test.cpp:7: undefined reference to `boost::date_time::gregorian_calendar_base<boost::date_time::year_month_day_base<boost::gregorian::greg_year, boost::gregorian::greg_month, boost::gregorian::greg_day>, unsigned long>::day_number(boost::date_time::year_month_day_base<boost::gregorian::greg_year, boost::gregorian::greg_month, boost::gregorian::greg_day> const&)' test.cpp:6: undefined reference to `boost::date_time::gregorian_calendar_base<boost::date_time::year_month_day_base<boost::gregorian::greg_year, boost::gregorian::greg_month, boost::gregorian::greg_day>, unsigned long>::from_day_number(unsigned long)' (snipped...) Best as I can tell (cd $BOOST_ROOT/boost/date_time && find . -name '*.cpp' -print), there are no .cpp files to be compiled... Anyone know what's up? --Eric _________________________________________________________________ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

Tuesday, February 25, 2003, 1:15:10 PM, you wrote: EC> I'm trying to test the date_time functionality of boost and am having some EC> difficulties. I would like to simply get the current local time into a ptime EC> and write it out as an ISO-8601 string. EC> Using Boost 1.29 and g++ 3.2, when I compile the following code I get a EC> number of *linker* errors. EC> Code: EC> #include <boost/date_time/posix_time/posix_time_types.hpp> EC> #include <boost/date_time/posix_time/time_formatters.hpp> EC> int main() EC> { EC> boost::posix_time::ptime pt = boost::posix_time::second_clock::local_time(); EC> std::cout << boost::posix_time::to_iso_extended_string(pt) << std::endl; EC> } EC> That code seems pretty straightforward to me. The linker errors look like EC> the following: EC> test.cpp:7: undefined reference to EC> `boost::date_time::gregorian_calendar_base<boost::date_time::year_month_day_base<boost::gregorian::greg_year, EC> boost::gregorian::greg_month, boost::gregorian::greg_day>, unsigned long>>::day_number(boost::date_time::year_month_day_base<boost::gregorian::greg_year, EC> boost::gregorian::greg_month, boost::gregorian::greg_day> const&)' EC> test.cpp:6: undefined reference to EC> `boost::date_time::gregorian_calendar_base<boost::date_time::year_month_day_base<boost::gregorian::greg_year, EC> boost::gregorian::greg_month, boost::gregorian::greg_day>, unsigned long>>::from_day_number(unsigned long)' EC> (snipped...) EC> Best as I can tell (cd $BOOST_ROOT/boost/date_time && find . -name '*.cpp' EC> -print), there are no .cpp files to be compiled... EC> Anyone know what's up? EC> --Eric EC> _________________________________________________________________ EC> Protect your PC - get McAfee.com VirusScan Online EC> http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 Tuesday, February 25, 2003, 1:15:10 PM, you wrote: EC> I'm trying to test the date_time functionality of boost and am having some EC> difficulties. I would like to simply get the current local time into a ptime EC> and write it out as an ISO-8601 string. EC> Using Boost 1.29 and g++ 3.2, when I compile the following code I get a EC> number of *linker* errors. EC> Code: EC> #include <boost/date_time/posix_time/posix_time_types.hpp> EC> #include <boost/date_time/posix_time/time_formatters.hpp> You need to include <boost/date_time/posix_time/posix_time.hpp> **Note - no _types at the end) to bring in the I/O stuff for dates and times. The same would go for just dates (gregorian.hpp instead of gregorian_types.hpp) HTH Steve -- Steve Love: steve.love@essennell.co.uk ACCU - accu.org Promoting Professionalism in Programming

Eric Crampton wrote:
I'm trying to test the date_time functionality of boost and am having some difficulties. I would like to simply get the current local time into a ptime and write it out as an ISO-8601 string.
Using Boost 1.29 and g++ 3.2, when I compile the following code I get a number of *linker* errors.
I've had a problem while using it with Borland C++Builder. The solution (which I think Jeff posted here a while back) is to #define DATE_TIME_INLINE before including the header files. This solved linker errors for me.
Best as I can tell (cd $BOOST_ROOT/boost/date_time && find . -name '*.cpp' -print), there are no .cpp files to be compiled...
In boost/libs/date_time/src there are 3 .cpp files which may need to be added (if you don't want to build the lib) which is the way I've done it. (in boost-1.29.0 anyway) Cheers Russell

Eric C wrote:
test.cpp:7: undefined reference to `boost::date_time::gregorian_calendar_base<boost::date_time::year_month_day_base<boost::gregorian::greg_year, boost::gregorian::greg_month, boost::gregorian::greg_day>, unsigned long>::day_number(boost::date_time::year_month_day_base<boost::gregorian::greg_year, boost::gregorian::greg_month, boost::gregorian::greg_day> const&)'
test.cpp:6: undefined reference to `boost::date_time::gregorian_calendar_base<boost::date_time::year_month_day_base<boost::gregorian::greg_year, boost::gregorian::greg_month, boost::gregorian::greg_day>, unsigned long>::from_day_number(unsigned long)'
(snipped...)
Best as I can tell (cd $BOOST_ROOT/boost/date_time && find . -name '*.cpp' -print), there are no .cpp files to be compiled...
The .cpp files are under libs/date_time/src.
Anyone know what's up?
With 1.29 you have to build and link the library. And don't forget to define DATE_TIME_INLINE. This has been cleaned up in 1.30. See http://www.boost.org/libs/date_time/doc/BuildInfo.html for more. Jeff
participants (4)
-
Eric Crampton
-
Jeff Garland
-
Russell Hind
-
Stephen Love