AVR STL on Mac OSX

Hello all,

I am working with the Arduino on a Mac OSX and I am attempting to use the std library structures. I checked on this thread already:
http://forum.arduino.cc/index.php?PHPSESSID=v0mtlekfh5tlutptr629pfirv4&topic=204225.0

I went to the site that was suggested to download the library:

However, the instructions said to put the include folder into the hardware/tools/avr/avr/include subdirectory of the Arduino installation. I am not sure where this directory is on a Mac OS X. I looked for it in my Libraries folder, and it was not there. There is the Arduino application in the Applications folder, and the libraries folder under my sketch folder. I tried putting the folder in the libraries folder in my sketch folder, but it did not work.

So does anyone have any suggestions? Thank you in advanced for any help.

You have to do “show package contents” on the Arduino app, in which case you’ll see:
Arduino.app/Contents/Resources/Java/Hardware/…

Okay so I copied the contents to the hardware/tools/avr/avr/include and then I created a simple library header file and sketch.

Here is the header file, which I called Blank.h:

#ifndef _BLANK_H
#define _BLANK_H

#include <queue>

queue<int> q;

#endif /*_BLANK_H*/

Here is my sketch Blank.ino:

#include <Blank.h>

void setup() {}
void loop() {}

Here are the top errors, I can’t put all of them since it exceeds the post limit, but these are the first errors.

In file included from /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_algobase.h:64,
                 from /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/queue:30,
                 from Documents/Arduino/libraries/Blank/Blank.h:4,
                 from Blank.ino:1:
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:589: error: expected type-specifier before 'char_traits'
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:589: error: expected '>' before 'char_traits'
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:595: error: expected ';' before '<' token
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:599: error: '_Dist' does not name a type
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:604: error: expected `)' before '&' token
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:623: error: expected ';' before '*' token
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h: In constructor 'std::istream_iterator<_Tp, _CharT, _Traits>::istream_iterator()':
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:603: error: class 'std::istream_iterator<_Tp, _CharT, _Traits>' does not have any field named '_M_stream'
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h: In member function 'bool std::istream_iterator<_Tp, _CharT, _Traits>::_M_equal(const std::istream_iterator<_Tp, _CharT, _Traits>&) const':
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:620: error: '_M_stream' was not declared in this scope
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h: In member function 'void std::istream_iterator<_Tp, _CharT, _Traits>::_M_read()':
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:628: error: '_M_stream' was not declared in this scope
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h: At global scope:
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:638: error: wrong number of template arguments (4, should be 3)
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:591: error: provided for 'template<class _Tp, class _CharT, class _Traits> class std::istream_iterator'
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:639: error: wrong number of template arguments (4, should be 3)
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:591: error: provided for 'template<class _Tp, class _CharT, class _Traits> class std::istream_iterator'
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:639: error: 'bool std::operator==(const int&, const int&)' must have an argument of class or enumerated type
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:647: error: wrong number of template arguments (4, should be 3)
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:591: error: provided for 'template<class _Tp, class _CharT, class _Traits> class std::istream_iterator'
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:648: error: wrong number of template arguments (4, should be 3)
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:591: error: provided for 'template<class _Tp, class _CharT, class _Traits> class std::istream_iterator'
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:648: error: 'bool std::operator!=(const int&, const int&)' must have an argument of class or enumerated type
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stl_iterator.h:655: error: expected type-specifier before 'char_traits'

I also tried the following in my header file, but got the same error:

#ifndef _BLANK_H
#define _BLANK_H

#include <queue>

avrstl::queue<int> q;

#endif /*_BLANK_H*/

So are these errors in the STL that I need to fix or did I do something wrong?

Thanks for any help.

As I mention in bold type on the page linked above:

You need to include or you will get compile errors.

This compiles OK (on a Mac):

#include <iterator>
#include <queue>

std::queue<int> q;

void setup ()
  {
  }  // end of setup

void loop () { }

Thank you very much, including iterator fixed the problem.

Okay now my problem is that I am trying to use the string find function; however, it gives me the following errors:

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/string: In instantiation of 'const size_t std::basic_string<char, std::char_traits<char>, std::allocator<char> >::npos':
Documents/Arduino/libraries/Blank/Blank.cpp:172:   instantiated from here
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/string:1106: error: dependent-name 'std::basic_string::size_type' is parsed as a non-type, but instantiation yields a type
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/string:1106: note: say 'typename std::basic_string::size_type' if a type is meant

I am trying to do something like the following:

void MatchKW(std::string keyword)
{	
	if(keyword.find("on") != std::string::npos)
	{
		// Do stuff
	}
	else if(keyword.find("off") != std::string::npos)
	{
		// Do stuff
	}
}

Thanks again for any help.

This compiled OK for me:

#include <iterator>
#include <string>

void MatchKW(std::string keyword)
{	
	if(keyword.find("on") != std::string::npos)
	{
		// Do stuff
	}
	else if(keyword.find("off") != std::string::npos)
	{
		// Do stuff
	}
}

void setup () {}
void loop () { }

Please post all your code, that demonstrates a problem, not snippets.

http://snippets-r-us.com/