Why won't this simple Boost string example compile?

Discussion in 'C++' started by Saqib Ali, Oct 17, 2011.

  1. Saqib Ali

    Saqib Ali Guest

    I'm using Solaris 10. And I'm trying to compile the simple Boost
    string program shown at the top of this link:

    http://www.boost.org/doc/libs/1_47_0/doc/html/string_algo/usage.html#id2895475

    Here is my compile line: /opt/solstudio12.2/bin/CC -c myTest.C -I /
    BOOST/include -o myTest.o

    But compilation fails and I can't figure out why. Here are the error
    messages:

    "myTest.C", line 43: Error: Cannot use std::string to initialize int.
    "myTest.C", line 44: Error: Cannot use std::string to initialize int.


    FYI, line 43 & 44 are

    to_upper(str1); // Line 43
    trim(str1); // Line 44

    Can anyone advise how to fix?

    - Saqib
    Saqib Ali, Oct 17, 2011
    #1
    1. Advertising

  2. Saqib Ali

    gwowen Guest

    Saqib Ali wrote:
    > "myTest.C", line 43: Error: Cannot use std::string to initialize int.
    > "myTest.C", line 44: Error: Cannot use std::string to initialize int.
    >
    >
    > FYI, line 43 & 44 are


    That simple example does not have 44 lines of code. Your problem lies
    in the code that you have not told us about.
    gwowen, Oct 17, 2011
    #2
    1. Advertising

  3. Saqib Ali

    Saqib Ali Guest


    > That simple example does not have 44 lines of code.  Your problem lies
    > in the code that you have not told us about.


    Ok. I guess that is a fair point. I had some white-space at the top of
    the file. Now I have removed it so it is identical to what is shown at
    the link I provided. Here is the error I'm getting:


    "myTest.C", line 8: Error: Cannot use std::string to initialize int.
    "myTest.C", line 9: Error: Cannot use std::string to initialize int.
    Saqib Ali, Oct 17, 2011
    #3
  4. Saqib Ali

    Saqib Ali Guest


    > That simple example does not have 44 lines of code.  Your problem lies
    > in the code that you have not told us about.


    Ok. Fair point I guess. I had a lot of white-space at the top of my
    file. I have now removed it so that it is exactly identical to the
    snippet found at the link I posted above. But I am getting the same
    error:

    "myTest.C", line 8: Error: Cannot use std::string to initialize int.
    "myTest.C", line 9: Error: Cannot use std::string to initialize int.
    Saqib Ali, Oct 17, 2011
    #4
  5. Saqib Ali

    gwowen Guest

    On Oct 17, 3:31 pm, Saqib Ali <> wrote:
    > > That simple example does not have 44 lines of code.  Your problem lies
    > > in the code that you have not told us about.

    >
    > Ok. I guess that is a fair point. I had some white-space at the top of
    > the file. Now I have removed it so it is identical to what is shown at
    > the link I provided. Here is the error I'm getting:
    >
    > "myTest.C", line 8: Error: Cannot use std::string  to initialize int.
    > "myTest.C", line 9: Error: Cannot use std::string  to initialize int.


    You need your function calls (i.e. to_upper(str1); trim(str1); ) to
    be either in some scope where such statements are valid - i.e. in a
    function scope such as main(), or initialising a file-scope/global-
    scope variable. What does the following say:

    #include <boost/algorithm/string.hpp>
    using namespace std;
    using namespace boost;

    int main(void)
    {
    string str1(" hello world! ");
    to_upper(str1); // str1 == " HELLO WORLD! "
    trim(str1); // str1 == "HELLO WORLD!"

    string str2=
    to_lower_copy(
    ireplace_first_copy(
    str1,"hello","goodbye")); // str2 == "goodbye world!"
    return(EXIT_SUCCESS)'
    }
    gwowen, Oct 17, 2011
    #5
  6. Saqib Ali

    Saqib Ali Guest

    Same Error:

    "myTest.C", line 11: Error: Could not find a match for
    std::string::basic_string(boost::transform_iterator<boost::algorithm::detail::to_lowerF<char>,
    const char*, boost::use_default, boost::use_default>,
    boost::transform_iterator<boost::algorithm::detail::to_lowerF<char>,
    const char*, boost::use_default, boost::use_default>) needed in
    boost::algorithm::detail::transform_range_copy<std::string,
    std::string, boost::algorithm::detail::to_lowerF<char>>(const
    std::string &, boost::algorithm::detail::to_lowerF<char>).



    On Oct 17, 11:20 am, gwowen <> wrote:
    > On Oct 17, 3:31 pm, Saqib Ali <> wrote:
    >
    > > > That simple example does not have 44 lines of code.  Your problem lies
    > > > in the code that you have not told us about.

    >
    > > Ok. I guess that is a fair point. I had some white-space at the top of
    > > the file. Now I have removed it so it is identical to what is shown at
    > > the link I provided. Here is the error I'm getting:

    >
    > > "myTest.C", line 8: Error: Cannot use std::string  to initialize int.
    > > "myTest.C", line 9: Error: Cannot use std::string  to initialize int.

    >
    > You need your function calls (i.e.  to_upper(str1); trim(str1); ) to
    > be either in some scope where such statements are valid - i.e. in a
    > function scope such as main(), or initialising a file-scope/global-
    > scope variable. What does the following say:
    >
    > #include <boost/algorithm/string.hpp>
    > using namespace std;
    > using namespace boost;
    >
    > int main(void)
    > {
    >     string str1(" hello world! ");
    >     to_upper(str1);  // str1 == " HELLO WORLD! "
    >     trim(str1);      // str1 == "HELLO WORLD!"
    >
    >     string str2=
    >        to_lower_copy(
    >           ireplace_first_copy(
    >              str1,"hello","goodbye")); // str2 == "goodbye world!"
    >     return(EXIT_SUCCESS)'
    >
    >
    >
    >
    >
    >
    >
    > }
    Saqib Ali, Oct 17, 2011
    #6
  7. On 17 oct, 19:42, Saqib Ali <> wrote:
    > Same Error:
    >
    > "myTest.C", line 11: Error: Could not find a match for
    > std::string::basic_string(boost::transform_iterator<boost::algorithm::detail::to_lowerF<char>,
    > const char*, boost::use_default, boost::use_default>,
    > boost::transform_iterator<boost::algorithm::detail::to_lowerF<char>,
    > const char*, boost::use_default, boost::use_default>) needed in
    > boost::algorithm::detail::transform_range_copy<std::string,
    > std::string, boost::algorithm::detail::to_lowerF<char>>(const
    > std::string &, boost::algorithm::detail::to_lowerF<char>).
    >
    > On Oct 17, 11:20 am, gwowen <> wrote:
    >
    >
    >
    >
    >
    >
    >
    > > On Oct 17, 3:31 pm, Saqib Ali <> wrote:

    >
    > > > > That simple example does not have 44 lines of code.  Your problemlies
    > > > > in the code that you have not told us about.

    >
    > > > Ok. I guess that is a fair point. I had some white-space at the top of
    > > > the file. Now I have removed it so it is identical to what is shown at
    > > > the link I provided. Here is the error I'm getting:

    >
    > > > "myTest.C", line 8: Error: Cannot use std::string  to initialize int.
    > > > "myTest.C", line 9: Error: Cannot use std::string  to initialize int.

    >
    > > You need your function calls (i.e.  to_upper(str1); trim(str1); ) to
    > > be either in some scope where such statements are valid - i.e. in a
    > > function scope such as main(), or initialising a file-scope/global-
    > > scope variable. What does the following say:

    >
    > > #include <boost/algorithm/string.hpp>
    > > using namespace std;
    > > using namespace boost;

    >
    > > int main(void)
    > > {
    > >     string str1(" hello world! ");
    > >     to_upper(str1);  // str1 == " HELLO WORLD! "
    > >     trim(str1);      // str1 == "HELLO WORLD!"

    >
    > >     string str2=
    > >        to_lower_copy(
    > >           ireplace_first_copy(
    > >              str1,"hello","goodbye")); // str2 == "goodbye world!"
    > >     return(EXIT_SUCCESS)'

    >
    > > }


    It may be a SunStudio related issue.
    Try the same with gcc.

    --
    Michael
    Michael DOUBEZ, Oct 18, 2011
    #7
  8. Saqib Ali

    Saqib Ali Guest


    > It may be a SunStudio related issue.
    > Try the same with gcc.
    >
    > --
    > Michael


    Interestingly, with gcc, compilation works:

    gcc -c myTest.C -I BOOST/include -o myTest.o

    But linking fails:

    gcc myTest.C -I BOOST/include -L BOOST/lib -lboost_thread_d -
    lboost_system_d -o myTest


    Test
    Undefined first referenced
    symbol in file
    __1cG__CrunKpure_error6F_v_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::basic_string(std::basic_string<char, std::char_traits<char>,

    std::allocator<char> > const&)/var/tmp//cc64pYPU.o
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::_Rep::_S_terminal/var/tmp//cc64pYPU.o

    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::eek:perator[](unsigned int) const/var/tmp//cc64pYPU.o

    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::end() const/var/tmp//cc64pYPU.o

    __1cG__CrunIex_alloc6FI_pv_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    __1cG__CrunIex_throw6Fpvpkn0AQstatic_type_info_pF1_v_v_ /vobs/zodiac/
    ADAT_base/BOOST/lib/libboost_thread_d.so
    __1cDstdJexceptionEwhat6kM_pkc_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    std::locale::locale(std::locale const&)/var/tmp//cc64pYPU.o
    __1cDstdMbasic_string4Ccn0ALchar_traits4Cc__n0AJallocator4Cc___2t6Mpkcrkn0C__v_ /
    vobs/zodiac/ADAT_base/BOOST/lib/libboost_thread_d.so
    __1cDstdNruntime_errorG__vtbl_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    __1cDstdMbasic_string4Ccn0ALchar_traits4Cc__n0AJallocator4Cc___2T6M_v_ /
    vobs/zodiac/ADAT_base/BOOST/lib/libboost_thread_d.so
    __1cDstdZ__RTTI__1nDstdJbad_alloc__ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::replace(__gnu_cxx::__normal_iterator<char*, std::basic_string<char,

    std::char_traits<char>, std::allocator<char> > >,
    __gnu_cxx::__normal_iterator<char*, std::basic_string<char,
    std::char_traits<char>, std::allocator<char> > >, char const*, char
    const*)/var/tmp//cc64pYPU.o
    __1cDstdNruntime_error2T6M_v_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    __1cG__CrunRex_chk_unexpected6F_v_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::_S_empty_rep()/var/tmp//cc64pYPU.o

    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::basic_string()/var/tmp//cc64pYPU.o

    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::~basic_string()/var/tmp//cc64pYPU.o

    __1cDstdMbasic_string4Ccn0ALchar_traits4Cc__n0AJallocator4Cc___J__nullref_ /
    vobs/zodiac/ADAT_base/BOOST/lib/libboost_thread_d.so
    __1cH__rwstdUInterlockedIncrement6Fpl_l_ /vobs/zodiac/ADAT_base/BOOST/
    lib/libboost_thread_d.so
    __cxa_end_catch /var/tmp//cc64pYPU.o
    std::ctype<char> const& std::use_facet<std::ctype<char> >(std::locale
    const&)/var/tmp//cc64pYPU.o
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::replace(__gnu_cxx::__normal_iterator<char*, std::basic_string<char,

    std::char_traits<char>, std::allocator<char> > >,
    __gnu_cxx::__normal_iterator<char*, std::basic_string<char,
    std::char_traits<char>, std::allocator<char> > >,
    __gnu_cxx::__normal_iterator<char const*, std::basic_string<char,
    std::char_traits<char>, std::allocator<char> > >,
    __gnu_cxx::__normal_iterator<char const*, std::basic_string<char,
    std::char_traits<char>, std::allocator<char> > >)/var/tmp//cc64pYPU.o
    __1cDstdMbasic_string4Ccn0ALchar_traits4Cc__n0AJallocator4Cc___I__getRep6MII_pnH__rwstdM__string_ref4Ccn0B_n0C____ /
    vobs/zodiac/ADAT_base/BOOST/lib/libboost_thread_d.so

    __cxa_begin_catch /var/tmp//cc64pYPU.o
    __1cDstdNruntime_error2T5B6M_v_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::end()/var/tmp//cc64pYPU.o

    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::basic_string(char const*, std::allocator<char> const&)/var/tmp//

    cc64pYPU.o
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::begin() const/var/tmp//cc64pYPU.o

    std::allocator<char>::~allocator() /var/tmp//cc64pYPU.o
    std::allocator<char>::allocator() /var/tmp//cc64pYPU.o
    __1c2n6FIpv_0_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    __1cDstdJexceptionG__vtbl_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    __1cDstdJbad_allocG__vtbl_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::_Rep::_M_refdata()/var/tmp//cc64pYPU.o

    __1cG__CrunMex_rethrow_q6F_v_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char>

    const&)/var/tmp//cc64pYPU.o
    __1cDstdMout_of_range2T5B6M_v_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::_Rep::_M_destroy(std::allocator<char> const&)/var/tmp//cc64pYPU.o

    std::ios_base::Init::~Init() /var/tmp//cc64pYPU.o
    std::ios_base::Init::Init() /var/tmp//cc64pYPU.o
    __1cDstdMout_of_rangeG__vtbl_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::begin()/var/tmp//cc64pYPU.o

    __gxx_personality_v0 /var/tmp//cc64pYPU.o
    __cxa_rethrow /var/tmp//cc64pYPU.o
    __1cG__CrunSregister_exit_code6FpG_v_v_ /vobs/zodiac/ADAT_base/BOOST/
    lib/libboost_system_d.so
    __1cG__CrunHex_skip6F_b_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::erase(__gnu_cxx::__normal_iterator<char*, std::basic_string<char,

    std::char_traits<char>, std::allocator<char> > >,
    __gnu_cxx::__normal_iterator<char*, std::basic_string<char,
    std::char_traits<char>, std::allocator<char> > >)/var/tmp//cc64pYPU.o
    __1cDstdMbasic_string4Ccn0ALchar_traits4Cc__n0AJallocator4Cc___I__unLink6M_v_ /
    vobs/zodiac/ADAT_base/BOOST/lib/libboost_thread_d.so
    std::locale::~locale() /var/tmp//cc64pYPU.o
    std::locale::locale() /var/tmp//cc64pYPU.o
    __1cG__CrunIex_clean6F_v_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    __1cG__CrunKex_rethrow6F_v_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::_Alloc_hider::_Alloc_hider(char*, std::allocator<char> const&)/var/

    tmp//cc64pYPU.o
    __1c2k6Fpv0_v_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    __1cDstdLlogic_errorG__vtbl_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >::size() const/var/tmp//cc64pYPU.o

    c::c(n6, (int0_t)) /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    __1c2k6Fpv_v_ /vobs/zodiac/ADAT_base/BOOST/lib/
    libboost_thread_d.so
    ld: fatal: Symbol referencing errors. No output written to myTest
    collect2: ld returned 1 exit status
    Saqib Ali, Oct 18, 2011
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,850
    Smokey Grindel
    Dec 2, 2006
  2. Replies:
    5
    Views:
    1,091
  3. Nagaraj
    Replies:
    1
    Views:
    856
    Lionel B
    Mar 1, 2007
  4. Replies:
    2
    Views:
    1,171
    Victor Bazarov
    Mar 26, 2009
  5. nudnik
    Replies:
    2
    Views:
    413
    Juha Nieminen
    Sep 28, 2012
Loading...

Share This Page