Pages: [1]   Go Down
Author Topic: Really basic question about creating a library  (Read 4306 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been unable to create a library. I tried the 'Morse' example in the tutorial. I cut-and-pasted the text in the tutorial into the appropriate .h file, .cpp file, and .pde.  I stored the .h and .cpp in the \hardware\libraries folder in a folder called Morse, just like in the tutorial. I made sure every time I compiled a sketch to remove the .o file from the Morse folder.

When I try to compile, I always get the following (I've tried Arduino release 13 and 14 under Windows XP):


[glow]In file included from C:\Program Files\arduino-0014\hardware\cores\arduino/WProgram.h:4,


c:/program files/arduino-0014/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'


c:/program files/arduino-0014/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'


c:/program files/arduino-0014/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'


In file included from C:\Program Files\arduino-0014\hardware\cores\arduino/WProgram.h:6,[/glow]

What am I doing wrong?

thanks
Bob
Logged

Indiana
Offline Offline
Full Member
***
Karma: 1
Posts: 234
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is due to changes from older versions of the IDE and apparently the code example has been updated.

Add this code to the bottom of your morse.h
Code:
#undef int
#undef char
#undef long
#undef byte
#undef float
#undef abs
#undef round

So now your morse.h file will look like this:
Code:
/*
  Morse.h - Library for flashing Morse code.
  Created by David A. Mellis, November 2, 2007.
  Released into the public domain.
*/

#ifndef Morse_h
#define Morse_h

#include "WConstants.h"

class Morse
{
  public:
    Morse(int pin);
    void dot();
    void dash();
  private:
    int _pin;
};

#undef int
#undef char
#undef long
#undef byte
#undef float
#undef abs
#undef round

#endif
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It works! Thanks for the advice.

Can you tell me why it works?

many thanks,
Bob
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had the same problem with a library I was building. I think they changed where some of these data types are getting defined in the standard headers, but I didn't really bother to look too deeply. Someone suggested a different workaround to me that I think is a little cleaner than the one etrace gave you:

1. In morse.h, change the line that reads:

Code:
#include "WConstants.h"
to read:

Code:
#include "WProgram.h"

2. Remove the following line from morse.cpp:

Code:
#include "WProgram.h"
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried your changes and they also work.

Many thanks!
Logged

Canton, Ohio
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It would be very helpful if the author of the site modified the tutorial on the library example for morse.  This was a very well written and helpful tutorial right up to the point when it will not compile in the program.

Since this is such an important building block in the arsenal of Arduino, it would be a shame to have people stumble here.

The fix posted here does allow the program to compile and work fine.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
meh
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It would be very helpful if the author of the site modified the tutorial on the library example for morse.  This was a very well written and helpful tutorial right up to the point when it will not compile in the program.

Since this is such an important building block in the arsenal of Arduino, it would be a shame to have people stumble here.

The fix posted here does allow the program to compile and work fine.

I agree.

I had the same errors listed at the top of this post when I added the LedControl library. I needed to make the same modifications to LedControl.cpp and LedControl.h to make them compile correctly.

I'm having even worse errors with the FrequencyTimer2 library (see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1239820770), and the changes listed above don't work at all.

But I wonder how many more libraries I will download that have the WConstants.h and WPrograms.h problem?  Is this because things got changed in 0015?  Is it because of my Duemilanove?  I'm pretty new at this, not a C/C++ guru by any means, and it's kinda frustrating....
Logged

Seattle, WA
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Just trying to get started (in a hurry!)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And to add to the grief and adding an example of the potential for wasted time, wait until the Newbies such as myself run into this.

I'm running OSX, and I too got the standard errors mentioned above.  

I tried both changes (after deleting the first one), and I get the following ugly bits for both solutions:

***********************************
/Applications/arduino-0014/hardware/libraries/Morse2/Morse.o: In function `Morse::dash()':

/Applications/arduino-0014/hardware/libraries/Morse2/Morse.cpp:24: multiple definition of `Morse::dash()'

/Applications/arduino-0014/hardware/libraries/Morse/Morse.o:/Applications/arduino-0014/hardware/libraries/Morse/Morse.cpp:24: first defined here

/Applications/arduino-0014/hardware/libraries/Morse2/Morse.o: In function `Morse::dot()':

/Applications/arduino-0014/hardware/libraries/Morse2/Morse.cpp:16: multiple definition of `Morse::dot()'

/Applications/arduino-0014/hardware/libraries/Morse/Morse.o:/Applications/arduino-0014/hardware/libraries/Morse/Morse.cpp:16: first defined here

/Applications/arduino-0014/hardware/libraries/Morse2/Morse.o: In function `Morse':

/Applications/arduino-0014/hardware/libraries/Morse2/Morse.cpp:10: multiple definition of `Morse::Morse(int)'

/Applications/arduino-0014/hardware/libraries/Morse/Morse.o:/Applications/arduino-0014/hardware/libraries/Morse/Morse.cpp:10: first defined here

/Applications/arduino-0014/hardware/libraries/Morse2/Morse.o: In function `Morse':

/Applications/arduino-0014/hardware/libraries/Morse2/Morse.cpp:10: multiple definition of `Morse::Morse(int)'

/Applications/arduino-0014/hardware/libraries/Morse/Morse.o:/Applications/arduino-0014/hardware/libraries/Morse/Morse.cpp:10: first defined here

Couldn't determine program size: hardware/tools/avr/bin/avr-size: '/tmp/build26855.tmp/SOS.hex': No such file
**********

Hopefully there will be a resolution to this soon.

B
Logged

Seattle, WA
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Just trying to get started (in a hurry!)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To the group,

Please excuse my first post.  Obviously I had a duplicate copy running around.  Made the second fix, and all is well.

Still, I hope the powers that be fix the tutorial.

Bob
Logged

Rome, Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just used the first suggestion on FrequencyTimer2 to great avail.  Thanks!

 smiley-wink
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I fixed the tutorial.  Sorry it took so long.
Logged

Pages: [1]   Go Up
Jump to: