Instalacja boosta na Ubu

0

Tym oto poleceniem magicznym: sudo apt-get install libboost1.48-dev próbowałem zainstalwoać boosta.

Mam exampla ze strony boosta, ot, takie cuś:

#include "boost/date_time/gregorian/gregorian.hpp"
  #include <iostream>
  #include <string>

  int
  main() 
  {

    using namespace boost::gregorian;

    try {
      // The following date is in ISO 8601 extended format (CCYY-MM-DD)
      std::string s("2001-10-9"); //2001-October-09
      date d(from_simple_string(s));
      std::cout << to_simple_string(d) << std::endl;
      
      //Read ISO Standard(CCYYMMDD) and output ISO Extended
      std::string ud("20011009"); //2001-Oct-09
      date d1(from_undelimited_string(ud));
      std::cout << to_iso_extended_string(d1) << std::endl;
      
      //Output the parts of the date - Tuesday October 9, 2001
      date::ymd_type ymd = d1.year_month_day();
      greg_weekday wd = d1.day_of_week();
      std::cout << wd.as_long_string() << " "
                << ymd.month.as_long_string() << " "
                << ymd.day << ", " << ymd.year
                << std::endl;

      //Let's send in month 25 by accident and create an exception
      std::string bad_date("20012509"); //2001-??-09
      std::cout << "An expected exception is next: " << std::endl;
      date wont_construct(from_undelimited_string(bad_date));
      //use wont_construct so compiler doesn't complain, but you wont get here!
      std::cout << "oh oh, you shouldn't reach this line: " 
                << to_iso_string(wont_construct) << std::endl;
    }
    catch(std::exception& e) {
      std::cout << "  Exception: " <<  e.what() << std::endl;
    }


    return 0;
  }

przy kompilacji g++ plik.cpp wypluwa:

/tmp/ccT1FGga.o: In function main': cos.cpp:(.text+0x1b1): undefined reference to boost::as_long_string() const'
cos.cpp:(.text+0x1be): undefined reference to boost::gregorian::greg_weekday::as_long_string() const' /tmp/ccT1FGga.o: In function unsigned short boost::month_str_to_ushortboost::gregorian::greg_month(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
cos.cpp:(.text._ZN5boost9date_time19month_str_to_ushortINS_9gregorian10greg_monthEEEtRKSs[unsigned short boost::month_str_to_ushortboost::gregorian::greg_month(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x97): undefined reference to boost::gregorian::greg_month::get_month_map_ptr()' /tmp/ccT1FGga.o: In function boost::month_formatter<boost::greg_month, boost::simple_format<char>, char>::format_month(boost::greg_month const&, std::basic_ostream<char, std::char_traits<char> >&)':
cos.cpp:(.text._ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_13simple_formatIcEEcE12format_monthERKS3_RSo[boost::month_formatter<boost::greg_month, boost::simple_format<char>, char>::format_month(boost::greg_month const&, std::basic_ostream<char, std::char_traits<char> >&)]+0x26): undefined reference to boost::gregorian::greg_month::as_short_string() const' cos.cpp:(.text._ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_13simple_formatIcEEcE12format_monthERKS3_RSo[boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::simple_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::basic_ostream<char, std::char_traits<char> >&)]+0x45): undefined reference to boost::as_long_string() const'
/tmp/ccT1FGga.o: In function boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::iso_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::basic_ostream<char, std::char_traits<char> >&)': cos.cpp:(.text._ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo[boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::iso_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::basic_ostream<char, std::char_traits<char> >&)]+0x26): undefined reference to boost::as_short_string() const'
cos.cpp:(.text._ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo[boost::month_formatter<boost::greg_month, boost::iso_format<char>, char>::format_month(boost::greg_month const&, std::basic_ostream<char, std::char_traits<char> >&)]+0x45): undefined reference to boost::gregorian::greg_month::as_long_string() const' /tmp/ccT1FGga.o: In function boost::month_formatter<boost::greg_month, boost::iso_extended_format<char>, char>::format_month(boost::greg_month const&, std::basic_ostream<char, std::char_traits<char> >&)':
cos.cpp:(.text._ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_19iso_extended_formatIcEEcE12format_monthERKS3_RSo[boost::month_formatter<boost::greg_month, boost::iso_extended_format<char>, char>::format_month(boost::greg_month const&, std::basic_ostream<char, std::char_traits<char> >&)]+0x26): undefined reference to boost::gregorian::greg_month::as_short_string() const' cos.cpp:(.text._ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_19iso_extended_formatIcEEcE12format_monthERKS3_RSo[boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::iso_extended_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::basic_ostream<char, std::char_traits<char> >&)]+0x45): undefined reference to boost::as_long_string() const'
collect2: ld returned 1 exit status

Czy czegoś nie doinstalowałem? Jak poprawnie zainstalować boosta na Ubuntu?

0

A opcje linkera gdzie? Niektóre rzeczy z boosta są header-only, ale to czego próbujesz tu użyć jest akurat z biblioteki dynamicznej. Musisz określić jak nazywa się ten plik a następnie do komendy dodać -lnazwa_pliku_z_biblioteka.

Przeczytaj to: http://www.boost.org/doc/libs/1_49_0/more/getting_started/unix-variants.html punky 3 i 6.

1 użytkowników online, w tym zalogowanych: 0, gości: 1