help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cannot compile hash_map from stlport


From: Jim Anderson
Subject: Re: cannot compile hash_map from stlport
Date: Mon, 12 Nov 2007 21:12:54 GMT
User-agent: Thunderbird 1.5.0.13 (X11/20070824)

Pedro Lamarão wrote:
On 7 nov, 01:40, Jim Anderson <ez...@ieee.org> wrote:
I'd like to use the hash_map template from the stlport which I
picked up at sourceforge.net (version 5.1.4). I installed the
library and then create the example given 
athttp://www.sgi.com/tech/stl/hash_map.html. I've attached
this example (sample.cc) and a simple makefile. The only change I've
made to the example is to add the #include statements
for iostream and hash_map.

---------------
When I compile, I get the following output:

g++ -I/home/jja/work/prog/dev/ind/include/stlport -o sample sample.cc
sample.cc: In function 'int main()':
sample.cc:15: error: 'hash_map' was not declared in this scope
sample.cc:15: error: expected primary-expression before 'const'
sample.cc:15: error: expected `;' before 'const'
sample.cc:17: error: 'months' was not declared in this scope
sample.cc:30: error: 'cout' was not declared in this scope
sample.cc:30: error: 'endl' was not declared in this scope
make: *** [sample] Error 1
----------------

I ran the sample program through cpp to verify that hash_map
is being read in. It appears to be read in, yet I'm getting
the error that 'hash_map' was not declared. I'm guessing
the error message is telling me that the template is not
instansiating the hash_map class that is needed, but I'm
not sure. Can anyone explain the error message and why
the SGI example will not compile?

The missing names are all in namespace std.

You are missing the proper using declarations.

--
 Pedro Lamarão



Pedro,

Thank you for the help. However, when I add the
'using namespace std;'
line to my code. I now get link time errors, which
can be seen in the file 'out' that I have attached.

To me it looks like problem with the stlport code.
If you have time to look at my source file (sample.cc)
and my makefile, I'd appreciate your opinion on
whether the source file should compile and link without
error.

If you can help again, I would appreicate the help.

Regards,
Jim Anderson



sample: sample.cc
        g++ -I/home/jja/work/prog/dev/ind/include/stlport -o sample sample.cc

clean:
        rm -rf sample
g++ -I/home/jja/work/prog/dev/ind/include/stlport -o sample sample.cc
/tmp/ccoEtAnc.o: In function `main':
sample.cc:(.text+0x16c): undefined reference to `stlpmtx_std::cout'
sample.cc:(.text+0x1b7): undefined reference to `stlpmtx_std::cout'
sample.cc:(.text+0x202): undefined reference to `stlpmtx_std::cout'
sample.cc:(.text+0x24d): undefined reference to `stlpmtx_std::cout'
/tmp/ccoEtAnc.o: In function 
`stlp_priv::_Vector_base<stlp_priv::_Slist_node_base*, 
stlpmtx_std::allocator<stlp_priv::_Slist_node_base*> >::_M_throw_length_error() 
const':
sample.cc:(.text._ZNK9stlp_priv12_Vector_baseIPNS_16_Slist_node_baseEN11stlpmtx_std9allocatorIS2_EEE21_M_throw_length_errorEv[stlp_priv::_Vector_base<stlp_priv::_Slist_node_base*,
 stlpmtx_std::allocator<stlp_priv::_Slist_node_base*> 
>::_M_throw_length_error() const]+0xe): undefined reference to 
`stlpmtx_std::__stl_throw_length_error(char const*)'
/tmp/ccoEtAnc.o: In function `stlpmtx_std::__node_alloc::deallocate(void*, 
unsigned int)':
sample.cc:(.text._ZN11stlpmtx_std12__node_alloc10deallocateEPvj[stlpmtx_std::__node_alloc::deallocate(void*,
 unsigned int)]+0x2a): undefined reference to 
`stlpmtx_std::__node_alloc::_M_deallocate(void*, unsigned int)'
/tmp/ccoEtAnc.o: In function `stlpmtx_std::__node_alloc::allocate(unsigned 
int&)':
sample.cc:(.text._ZN11stlpmtx_std12__node_alloc8allocateERj[stlpmtx_std::__node_alloc::allocate(unsigned
 int&)]+0x2b): undefined reference to 
`stlpmtx_std::__node_alloc::_M_allocate(unsigned int&)'
/tmp/ccoEtAnc.o: In function `stlpmtx_std::ios_base::_M_check_exception_mask()':
sample.cc:(.text._ZN11stlpmtx_std8ios_base23_M_check_exception_maskEv[stlpmtx_std::ios_base::_M_check_exception_mask()]+0x1f):
 undefined reference to `stlpmtx_std::ios_base::_M_throw_failure()'
/tmp/ccoEtAnc.o: In function `stlpmtx_std::ios_base::getloc() const':
sample.cc:(.text._ZNK11stlpmtx_std8ios_base6getlocEv[stlpmtx_std::ios_base::getloc()
 const]+0x1a): undefined reference to 
`stlpmtx_std::locale::locale(stlpmtx_std::locale const&)'
/tmp/ccoEtAnc.o: In function `stlpmtx_std::num_put<char, 
stlpmtx_std::ostreambuf_iterator<char, stlpmtx_std::char_traits<char> > >* 
stlpmtx_std::_UseFacet<stlpmtx_std::num_put<char, 
stlpmtx_std::ostreambuf_iterator<char, stlpmtx_std::char_traits<char> > > 
>(stlpmtx_std::locale const&, stlpmtx_std::num_put<char, 
stlpmtx_std::ostreambuf_iterator<char, stlpmtx_std::char_traits<char> > > 
const*)':
sample.cc:(.text._ZN11stlpmtx_std9_UseFacetINS_7num_putIcNS_19ostreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEPT_RKNS_6localeEPKS7_[stlpmtx_std::num_put<char,
 stlpmtx_std::ostreambuf_iterator<char, stlpmtx_std::char_traits<char> > >* 
stlpmtx_std::_UseFacet<stlpmtx_std::num_put<char, 
stlpmtx_std::ostreambuf_iterator<char, stlpmtx_std::char_traits<char> > > 
>(stlpmtx_std::locale const&, stlpmtx_std::num_put<char, 
stlpmtx_std::ostreambuf_iterator<char, stlpmtx_std::char_traits<char> > > 
const*)]+0x15): undefined reference to 
`stlpmtx_std::locale::_M_use_facet(stlpmtx_std::locale::id const&) const'
/tmp/ccoEtAnc.o: In function `stlpmtx_std::basic_ostream<char, 
stlpmtx_std::char_traits<char> >& stlp_priv::__put_num<char, 
stlpmtx_std::char_traits<char>, long>(stlpmtx_std::basic_ostream<char, 
stlpmtx_std::char_traits<char> >&, long)':
sample.cc:(.text._ZN9stlp_priv9__put_numIcN11stlpmtx_std11char_traitsIcEElEERNS1_13basic_ostreamIT_T0_EES8_T1_[stlpmtx_std::basic_ostream<char,
 stlpmtx_std::char_traits<char> >& stlp_priv::__put_num<char, 
stlpmtx_std::char_traits<char>, long>(stlpmtx_std::basic_ostream<char, 
stlpmtx_std::char_traits<char> >&, long)]+0x10c): undefined reference to 
`stlpmtx_std::locale::~locale()'
sample.cc:(.text._ZN9stlp_priv9__put_numIcN11stlpmtx_std11char_traitsIcEElEERNS1_13basic_ostreamIT_T0_EES8_T1_[stlpmtx_std::basic_ostream<char,
 stlpmtx_std::char_traits<char> >& stlp_priv::__put_num<char, 
stlpmtx_std::char_traits<char>, long>(stlpmtx_std::basic_ostream<char, 
stlpmtx_std::char_traits<char> >&, long)]+0x11f): undefined reference to 
`stlpmtx_std::locale::~locale()'
collect2: ld returned 1 exit status
make: *** [sample] Error 1

#include <iostream>
#include <hash_map>

using namespace std;

struct eqstr
{
        bool operator()(const char* s1, const char* s2) const
        {
                return strcmp(s1, s2) == 0;
        }
};

int main()
{
        hash_map<const char*, int, hash<const char*>, eqstr> months;

        months["january"] = 31;
        months["february"] = 28;
        months["march"] = 31;
        months["april"] = 30;
        months["may"] = 31;
        months["june"] = 30;
        months["july"] = 31;
        months["august"] = 31;
        months["september"] = 30;
        months["october"] = 31;
        months["november"] = 30;
        months["december"] = 31;
  
        std::cout << "september -> " << months["september"] << endl;
        std::cout << "april     -> " << months["april"] << endl;
        std::cout << "june      -> " << months["june"] << endl;
        std::cout << "november  -> " << months["november"] << endl;
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]