🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

More Linux Complier Errors

Started by
3 comments, last by T1Oracle 16 years, 11 months ago

// in header file included in all sources
#ifdef linux
#include <ext/hash_map>
namespace stdext = __gnu_cxx;
#endif
#ifdef MSWINDOWS
#include <hash_map>
#endif

#1

inline static keyType_t Hash(const std::string &path) { return stdext::hash_map<std::string,Entry>::hasher(path); }; // hash function

Quote: Code Blocks error /home/bernard/C++ Projects/glfwHello/PakFile.h:18: error: no matching function for call to ‘__gnu_cxx::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::hash(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)’ /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ext/hash_fun.h:71: note: candidates are: __gnu_cxx::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::hash() /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ext/hash_fun.h:71: note: __gnu_cxx::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::hash(const __gnu_cxx::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)
#2

// reads count objects into output iterator dest
template <typename Stream,typename OutputIterator>
void Read(Stream &s,OutputIterator &dest, boost::uint32_t count)
{
    typename OutputIterator::value_type temp;
    while (count--)
    {
        Read(s,temp);
        *dest++=temp;
    }
}
Quote: Code Blocks error /home/bernard/C++ Projects/glfwHello/PakFile.cpp:93: instantiated from here /home/bernard/C++ Projects/glfwHello/iolib.h:13: error: variable or field ‘temp’ declared void
Instantiated from this code:

std::back_insert_iterator <std::string> it=std::back_inserter(fname);
iol::Read(fs,it,nameLen);
For MSVC8 I had that code written as

iol::Read(fs,std::back_inserter(fname),nameLen);
But I don't think Linux liked that. fname is an std::string and nameLen is an unsinged 32 bit integer representing the length of fname in number of chars. #3 On top of all of that it no longer likes the CML library which was compiling just fine before I added all of my sources and headers to my project.

template < typename Real, typename E, class A > void
get_frustum_corners(Real planes[6][4], vector<E,A> corners[8])
{
    enum { LEFT, RIGHT, BOTTOM, TOP, NEAR, FAR };

    corners[0] =
        detail::intersect_planes(planes, planes[BOTTOM], planes[NEAR]);
    corners[1] =
        detail::intersect_planes(planes, planes[BOTTOM], planes[NEAR]);
    corners[2] =
        detail::intersect_planes(planes, planes[TOP], planes[NEAR]);
    corners[3] =
        detail::intersect_planes(planes, planes[TOP], planes[NEAR]);
    corners[4] =
        detail::intersect_planes(planes, planes[BOTTOM], planes[FAR]);
    corners[5] =
        detail::intersect_planes(planes, planes[BOTTOM], planes[FAR]);
    corners[6] =
        detail::intersect_planes(planes, planes[TOP], planes[FAR]);
    corners[7] =
        detail::intersect_planes(planes, planes[TOP], planes[FAR]);
}
Quote: Code Blocks error cml::get_frustum_corners(Real (*)[4], cml::vector<E, AT>*)’: /home/bernard/Development_Tools/Libs/cml_1_0b1/cml/mathlib/frustum.h:194: error: expected primary-expression before ‘]’ token /home/bernard/Development_Tools/Libs/cml_1_0b1/cml/mathlib/frustum.h:196: error: expected primary-expression before ‘]’ token /home/bernard/Development_Tools/Libs/cml_1_0b1/cml/mathlib/frustum.h:198: error: expected primary-expression before ‘]’ token /home/bernard/Development_Tools/Libs/cml_1_0b1/cml/mathlib/frustum.h:200: error: expected primary-expression before ‘]’ token
Programming since 1995.
Advertisement
I found a solution for those errors:
inline static keyType_t Hash(const std::string &path) { return stdext::hash<char*>()(path.c_str()); }; // hash function

Fixed the first one, although I don't know if MVSC8 will compile that.

I fixed #2 by making another template that lets me set the value type, but I am still clueless as to why std::string::iterator::value_type==void?

I fixed #3 (at least it looks like it's solved) by putting cml/cml.h first in my header file.

Now I'm having difficulties getting libpng an freetype 2 to cooperate.
Programming since 1995.
hash_map::hasher isn't a function, but the type of a function. You have to "call" it twice: "stdext::hash_map<std::string, Entry>::hasher()(path)".

However, the default hash functor isn't, by default, overloaded for std::string. You'll either have to provide your own overload:
namespace stdext {  template<>  struct hash<std::string>  {    size_t    operator()(const std::string & __str) const    { return __stl_hash_string(__str.c_str()); }  };}

or store C strings in the hash.

std::back_insert_iterator <std::string>::value_type being void is, surprisingly, supported by the standard. Both the value_type and difference_type members of an output iterator are specified to be void. (STD: 24.3.1/1) Hopefully that weirdness will be fixed in the next version of the standard.

Since there are only four errors and they're all spaced two lines apart for the CML bug, I'd guess that either NEAR or FAR is defined as a macro.
Thanks, I think I'm going to replace the use of hash_map, none of my code that uses it will compile. Even this fails:
	// loads objects not found in pool from SourceT source	template <typename T,typename SourceT,typename ParamT=const char *>	class Pool	{	public:		typedef stdext::hash_map<ParamT,T> map_t;		Pool(SourceT source_) : source(source_) { };		// retrieves reference T object specified by the param parameters		void operator()(T &object,ParamT param)		{			map_t::iterator it=loadedMap.find(param);			if (it==loadedMap.end())			{ // not found then load and add it				source(object,param);				loadedMap[param]=object;			}			else // return it				object=*it;		};	private:		SourceT source; // input source object		map_t loadedMap; // map of loaded objects	};

Quote: Code Blocks error
error: expected ';' before 'it'

I wonder if there is a good boost libraries solution. I see that there is boost::hash but I still haven't figured out how to make it into a replacement for hash_map.

I know that google has a solution, and that I could install the SGI library, but I already have boost and I would like as little hassle as possible.

I have CML working already, I guess including one of my other headers before it messed with it.
Programming since 1995.
Note: I already fixed the issues above. I'm using tr1::unordered_map with boost::hash.

How is it that this works fine on windows using MSVC8 but on Kubuntu using Code::Blocks and gcc it causes a segmentation fault or fails to load the texture?

if (genMipmaps) // generate mipmaps    gluBuild2DMipmaps(GL_TEXTURE_2D, raw.NChannels(), raw.Width(),        raw.Height(), pxType, GL_UNSIGNED_BYTE, &(*raw.pixels.begin()));else // upload texture as mipmap level 0    UploadMipmapLvl(pxType,0,raw);

// UploadMipmapLvl(GLenum pxType_,unsigned short idx_,bmp::RawData &raw) calls thisglTexImage2D(GL_TEXTURE_2D,idx,raw.NChannels(),raw.Width(),raw.Height(),    0,pxType,GL_UNSIGNED_BYTE,&(*raw.pixels.begin()));


When genMipmaps==true I get a segmentation fault, when it is false the textured quad doesn't have a texture.

raw.Height() returns the height of the bitmap in pixels
raw.Width() returns the width of the bitmap in pixels
raw.NChannels() returns the number of color channels (in this case 3 for the RGB test image, which is loaded from a png)
raw.pixels is a std::vector<unsigned char> of the pixels in the image

*edit*
I need to get over my fear of Linux and stop posting these threads. All I needed to do was enable TEXTURE_2D before calling glGenTextures. I feel so silly.

[Edited by - T1Oracle on July 16, 2007 6:14:09 AM]
Programming since 1995.

This topic is closed to new replies.

Advertisement