Including STL in source where a header already calls it
Question
I am running ARtoolkit on Mac OS X Lion (using SDK 10.5, as per ARtoolkit instructions) and would like to include the vector library.
However, it seems that I cannot do this, and don't understand why. At first I thought it was an issue with the toolkit using an old SDK, but in digging through I see that stl_vector.h is included at some point, and when I include vector (or stl_vector for that matter), I get a heap of error messages dumped upon me.
Is there any way around this so that I can use vectors?
Here are my include paths:
#ifdef _WIN32
# include <windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#ifndef __APPLE__
# include <GL/glut.h>
#else
# include <GLUT/glut.h>
#endif
#include <AR/gsub.h>
#include <AR/param.h>
#include <AR/ar.h>
#include <AR/video.h>
#include <time.h>
#include "object.h"
#include <vector>
using namespace std;
Here are the errors that I'm seeing...
/Developer/SDKs/MacOSX10.5.sdk/usr/include/c++/4.2.1/bits/stl_vector.h
Expected type-specifier before 'allocator'
Expected '>' before 'allocator'
'input_iterator_tag' has not been declared
'forward_iterator_tag' has not been declared
'input_iterator_tag' has not been declared
'forward_iterator_tag' has not been declared
'input_iterator_tag' has not been declared
'forward_iterator_tag' has not been declared
There are no arguments to '__N' that depend on a template parameter, so a declaration of '__N' must be available
(if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
Expected nested-name-specifier before 'iterator_traits'
Expected initializer before '<' token
There are no arguments to '_IterCategory' that depend on a template parameter, so a declaration of '_IterCategory' must be available
Expected nested-name-specifier before 'iterator_traits'
Expected initializer before '<' token
There are no arguments to '_IterCategory' that depend on a template parameter, so a declaration of '_IterCategory' must be available
Expected nested-name-specifier before 'iterator_traits'
Expected initializer before '<' token
There are no arguments to '_IterCategory' that depend on a template parameter, so a declaration of '_IterCategory' must be available
/Developer/SDKs/MacOSX10.5.sdk/usr/include/c++/4.2.1/bits/allocator.h
Bits/c++allocator.h: No such file or directory
Expected template-name before '<' token
Expected `{' before '<' token
Expected unqualified-id before '<' token
/Developer/SDKs/MacOSX10.5.sdk/usr/include/c++/4.2.1/bits/stl_bvector.h
Expected template-name before '<' token
Expected `{' before '<' token
Expected unqualified-id before '<' token
/Developer/SDKs/MacOSX10.5.sdk/usr/include/c++/4.2.1/bits/stl_algobase.h
Bits/c++config.h: No such file or directory
/Developer/SDKs/MacOSX10.5.sdk/usr/include/c++/4.2.1/iosfwd
Bits/c++locale.h: No such file or directory
Bits/c++io.h: No such file or directory
Solution
Ugh. This makes me hate Xcode even more.
In order to fix this, I first converted the project to C++ (renamed files to *.cpp, set compile mode to C++ only), then upgraded the SDK to 10.6 (10.5 originally was the only one to work before converting to C++).
Once this was done, I was able to include vector without any issue. It was just an SDK problem in the end.