Why won't this simple Boost string example compile?

S

Saqib Ali

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
 
G

gwowen

Saqib said:
"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.
 
S

Saqib Ali

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.
 
S

Saqib Ali

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.
 
G

gwowen

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)'
}
 
S

Saqib Ali

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>).
 
M

Michael DOUBEZ

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>).

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

Saqib Ali

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

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
::basic_string(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&)/var/tmp//cc64pYPU.o
::_Rep::_S_terminal/var/tmp//cc64pYPU.o
::eek:perator[](unsigned int) const/var/tmp//cc64pYPU.o
::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
::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
::_S_empty_rep()/var/tmp//cc64pYPU.o
::basic_string()/var/tmp//cc64pYPU.o
::~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
::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
::end()/var/tmp//cc64pYPU.o
::basic_string(char const*, std::allocator<char> const&)/var/tmp//
cc64pYPU.o
::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
::_Rep::_M_refdata()/var/tmp//cc64pYPU.o
__1cG__CrunMex_rethrow_q6F_v_ /vobs/zodiac/ADAT_base/BOOST/lib/
libboost_thread_d.so
::_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
::_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
::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
::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
::_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
::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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top