sparse-hash Compilation problems

63 views
Skip to first unread message

neerajk

unread,
Apr 29, 2005, 2:17:39 AM4/29/05
to google-s...@googlegroups.com
a trivial test program:

#include <google/sparse_hash_map>

using namespace google;


int main(int argc, char* argv[]) {
sparse_hash_map<unsigned long long, unsigned int> test;
}

sparse_hash_map:133: parse error before `<'
sparse_hash_map:147: `SelectKey' was not declared in this scope
sparse_hash_map:147: `EqualKey' was not declared in this scope
sparse_hash_map:147: `Alloc' was not declared in this scope
sparse_hash_map:147: syntax error before `;'
sparse_hash_map:148: syntax error before `;'
sparse_hash_map:152: confused by earlier errors, bailing out

the library was configured with --enable-namespace=google

The question is why is it trying to compile the template before a call
is made? I understood that compilation of templates is on-demand.

Craig Silverstein

unread,
Apr 29, 2005, 7:43:39 AM4/29/05
to google-s...@googlegroups.com
} The question is why is it trying to compile the template before a
} call is made? I understood that compilation of templates is
} on-demand.

It's not trying to compile it: it's just trying to parse it.

} sparse_hash_map:133: parse error before `<'

This indicates to me that the definition of STL_NAMESPACE is weird.
Can you see what that's defined to in your config.h? Perhaps just
post the entire contents of /usr/include/google/sparsehash/config.h

craig

neerajk

unread,
Apr 29, 2005, 2:05:00 PM4/29/05
to google-s...@googlegroups.com
STL_NAMESPACE is std

And here's the complete config.h

/* src/google/sparsehash/config.h. Generated by configure. */
/* src/google/sparsehash_config.h.in. Generated from configure.ac by
autoheader. */


/* Namespace for Google classes */
#define GOOGLE_NAMESPACE google


/* the namespace of hash_map */
#define HASH_NAMESPACE std


/* Define to 1 if you have the <ext/hash_fun.h> header file. */
/* #undef HAVE_EXT_HASH_FUN_H */


/* define if the compiler has hash_map */
/* #undef HAVE_EXT_HASH_MAP */


/* define if the compiler has hash_set */
/* #undef HAVE_EXT_HASH_SET */


/* Define to 1 if you have the <ext/stl_hash_fun.h> header file. */
/* #undef HAVE_EXT_STL_HASH_FUN_H */


/* Define to 1 if you have the <hash_fun.h> header file. */
/* #undef HAVE_HASH_FUN_H */


/* define if the compiler has hash_map */
#define HAVE_HASH_MAP 1


/* define if the compiler has hash_set */
#define HAVE_HASH_SET 1


/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1


/* Define to 1 if you have the `memcpy' function. */
#define HAVE_MEMCPY 1


/* Define to 1 if you have the `memmove' function. */
#define HAVE_MEMMOVE 1

/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1


/* define if the compiler implements namespaces */
#define HAVE_NAMESPACES 1


/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1


/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1


/* Define to 1 if you have the <stl_hash_fun.h> header file. */
#define HAVE_STL_HASH_FUN_H 1


/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1


/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1


/* Define to 1 if you have the <sys/resource.h> header file. */
#define HAVE_SYS_RESOURCE_H 1


/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1


/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1


/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1


/* Name of package */
#define PACKAGE "sparsehash"

/* Define to the address where bug reports for this package should be
sent. */
#define PACKAGE_BUGREPORT "opens...@google.com"


/* Define to the full name of this package. */
#define PACKAGE_NAME "sparsehash"


/* Define to the full name and version of this package. */
#define PACKAGE_STRING "sparsehash 0.1"


/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "sparsehash"


/* Define to the version of this package. */
#define PACKAGE_VERSION "0.1"


/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1


/* the namespace where STL code like vector<> is defined */
#define STL_NAMESPACE std


/* does STL support iterator-tags? */
#define UNDERSTANDS_ITERATOR_TAGS 1


/* Version number of package */
#define VERSION "0.1"


/* Stops putting the code inside the Google namespace */
#define _END_GOOGLE_NAMESPACE_ };


/* Puts following code inside the Google namespace */
#define _START_GOOGLE_NAMESPACE_ namespace GOOGLE_NAMESPACE {

neerajk

unread,
Apr 29, 2005, 3:11:31 PM4/29/05
to google-s...@googlegroups.com
I ran configure again and there were warning messages which i had
ignored earlier

configure: WARNING: stl_hash_fun.h: present but cannot be compiled
configure: WARNING: stl_hash_fun.h: check for missing prerequisite
headers?
configure: WARNING: ## ------------------------------------ ##
configure: WARNING: ## Report this to bug-au...@gnu.org. ##
configure: WARNING: ## ------------------------------------ ##

Also, i tried compiling my test program with gcc 3.3.4 (earlier it was
2.95.3)
and i get

In file included from ......./sparse_hash_map:81,
from MapperTest.cpp:4:
....../google/sparsehash/hash_fun.h:1:26: stl_hash_fun.h: No such file
or directory

followed by earlier errors.
So the error is due to
class HashFcn = HASH_NAMESPACE::hash<Key> (?)

neerajk

unread,
Apr 29, 2005, 3:26:20 PM4/29/05
to google-s...@googlegroups.com
Problem fixed :)

I recompiled the library with g++ 3.3.4 and also all subsequent test
programs. That fixed it.

Interestingly make fails with gcc 3.3.4 (!!)
and configure is incorrect with gcc 2.95.3 (!)

Thank you for you help.

Craig Silverstein

unread,
Apr 29, 2005, 4:50:04 PM4/29/05
to google-s...@googlegroups.com
} Interestingly make fails with gcc 3.3.4 (!!) and configure is
} incorrect with gcc 2.95.3 (!)

Interesting; we've tested on both and it works fine. I'll keep this
in mind and see if we can figure out what was going on.

Glad you got things fixed.

craig

Tushar

unread,
May 10, 2005, 5:39:03 PM5/10/05
to google-s...@googlegroups.com
I'm trying to compile the sparse_hash_map on a Solaris 8 machine using
gcc 2.95.2 and am getting the same error message neerajk reported.
Configure also reported the same warnings. The classes were
configured to be defined in namespace std.

I found out that if the files stl_algobase.h and stl_function.h are
included in that order before including the sparse hash map files, the
compiler is happy. Any idea what is going on?

Thanks for your time.

Here is my test program

#include <iostream>

#include <stl_algobase.h>
#include <stl_function.h>

#include "google/sparsetable"
#include "google/sparse_hash_map"

int main()
{
std::sparsetable<int> test(100);

test[0] = 1000000;

std::cout << test[0] << endl;
std::cout << test[1] << endl;
std::cout << test.size() << endl;
std::cout << test.test(0) << endl;
std::cout << test.test(1) << endl;

std::sparse_hash_map<unsigned int, unsigned int> trial;
}

Craig Silverstein

unread,
May 11, 2005, 4:48:58 PM5/11/05
to google-s...@googlegroups.com
} I found out that if the files stl_algobase.h and stl_function.h are
} included in that order before including the sparse hash map files, the
} compiler is happy. Any idea what is going on?

My guess is that the sparse_hash_map code isn't #including everything
it needs to. On many systems it doesn't matter because other files it
includes bring in the right files for you, but on some systems (such
as yours), it does matter.

I'll look into fixing this for the next release. Thanks for the
report of the fix; that will help me figure out what we need to do.

craig
Reply all
Reply to author
Forward
0 new messages