Pages: [1]   Go Down
Author Topic: Cannot Find WProgram.h (differant)  (Read 4933 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so here is the deal,

Environment:
Compiled from Git Repo
Ubuntu x64

Last night I was successful at doing the blinking light tutorial using the sketch window. Now I want to create a C Library to do the Morse example. I am trying to do this in C instead of C++ but which I don't think should be that tough, but I am no expert. So I create the following in ./libraries/Morse

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 <WProgram.h>

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

#endif
Morse.H

Code:
#include "WProgram.h"
#include "Morse.h"

Morse::Morse(int pin)
{
  pinMode(pin, OUTPUT);
  _pin = pin;
}

void Morse::dot()
{
  digitalWrite(_pin, HIGH);
  delay(250);
  digitalWrite(_pin, LOW);
  delay(250); 
}

void Morse::dash()
{
  digitalWrite(_pin, HIGH);
  delay(1000);
  digitalWrite(_pin, LOW);
  delay(250);
}
Morse.c

Now comes the tricky part, first if I try to do what I want (which is compile using gcc Morse) I get the following...

Code:
jackie@jackie-Latitude-E6410:~/Development/Code/Arduino/libraries/Morse$ gcc Morse.c
Morse.c:1:22: fatal error: WProgram.h: No such file or directory
compilation terminated.

And if I use the sketch window I get the following...

Code:
     [exec]
     [exec]
     [exec]
     [exec]
     [exec]
     [exec]
     [exec]
     [exec]
     [exec]
     [exec]
     [exec] In file included from /home/jackie/Development/Code/Arduino/build/linux/work/libraries/Morse/Morse.c:2:
     [exec] /home/jackie/Development/Code/Arduino/build/linux/work/libraries/Morse/Morse.h:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Morse’
     [exec] /home/jackie/Development/Code/Arduino/build/linux/work/libraries/Morse/Morse.c:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
     [exec] /home/jackie/Development/Code/Arduino/build/linux/work/libraries/Morse/Morse.c:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
     [exec] /home/jackie/Development/Code/Arduino/build/linux/work/libraries/Morse/Morse.c:18: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token

Any ideas?

Thanks!
Logged

Connecticut
Offline Offline
Edison Member
*
Karma: 17
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In morse.c, change "wprogram" to <wprogram>

http://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename
Logged

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

Changed to...
Code:
#include <WProgram.h>
#include "Morse.h"
Also tried
Code:
#include <WProgram.h>
#include <Morse.h>

Response

Code:
jackie@jackie-Latitude-E6410:~/Development/Code/Arduino/libraries/Morse$ gcc Morse.c
Morse.c:1:22: fatal error: WProgram.h: No such file or directory
compilation terminated.

Code:
jackie@jackie-Latitude-E6410:~/Development/Code/Arduino/libraries/Morse$ ls
Morse.c  Morse.h

I will go over the link in a bit, any other ideas in the meantime?
Logged

Connecticut
Offline Offline
Edison Member
*
Karma: 17
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What happens if you don't include it?
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The WProgram.h should be added by the Arduino package by default. Mine does.
It is in the Arduino includes if you need it outside the Arduino package.
/arduino/cores/arduino/WProgram.h

Try adding a return type for the Morse function. Like this:
Code:
void Morse::Morse(int pin)
{
  pinMode(pin, OUTPUT);
  _pin = pin;
}

Change it in the Morse.h file also.
Code:
class Morse
{
  public:
    void Morse(int pin);
    void dot();
    void dash();

ADD: To stay with the norms of the Arduino/Atmel code, I would have called that function
Code:
void Morse::begin(int pin)
I see who wrote that Morse program. Isn't this the guy that maintains the Arduino IDE?
I like to know what weaknesses a programmer has if I am about to troubleshoot other code by the same programmer.

BTW, mine is mismatched curly braces. If I post code here, that is the first thing you should check.
That is why I may seem so anal about the curly brace alignment and indentation on my code.
« Last Edit: August 25, 2011, 06:28:09 am by SurferTim » Logged

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

Thanks I will try this... remember when it come to "should be included" that I am compiling this from source and not using apt-get or something similar. Again I am a little new to C do you know how to include a header file from another directory?
Logged

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

P.S. I don't see that header. Do I need to compile something differantly?


Code:
jackie@jackie-Latitude-E6410:~/Development/Code/Arduino/core$ ls
api.txt  build.xml  done.txt     make.sh  preproc     src
bin      core.jar   license.txt  methods  preproc.pl  todo.txt

Jackie
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That directory listing appears to be the build directory. If you want to know if it is working, try this short code. If the noTone function does not generate a compiler error, the WProgram.h file has been included.
Code:
void setup()
{
  noTone(13);  
}

void loop()
{
  
}
These both include a header file. The first includes the WProgram.h file from the default include directory. The second includes the file from the current directory.
Code:
#include <WProgram.h>
#include "WProgram.h"
I do not need either of those to compile that code in the Arduino IDE.
« Last Edit: August 26, 2011, 04:55:37 am by SurferTim » Logged

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

So after I execute ant on the build directory, where does it get built to? Do I have to have the header file in my classpath like Java? Where would the header file be after I built the project?
Logged

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

Finally found the WProgram.h file it is in...

./hardware/arduino/cores/arduino

Anyone have any helpful tips on how to include or install it?
Logged

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

Tried this... no dice still...

Code:
jackie@jackie-Latitude-E6410:~/Development/Code/Arduino/libraries/Morse$ gcc -I ../../hardware/arduino/cores/arduino/ -c ./Morse.c
In file included from ./Morse.c:1:0:
../../hardware/arduino/cores/arduino/WProgram.h:8:27: fatal error: avr/interrupt.h: No such file or directory
compilation terminated.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My apology for not getting back to you sooner. It was imperative I get my version of the Arduino compiler working.

You should be able to put it in the same directory as your code.
Then use
#include "WProgram.h"

EDIT: I see you have other challenges with the includes in the WProgram.h file.

I suggest remove the
#include "Wprogram.h"
statement from the code. That code shouldn't need it. There is nothing but setting pins and delay().

I took a look at the WProgram.h file. It appears to be a function set for producing an audible tone if you had an audio amp connected. Not required if you are just flashing the pin 13 LED.

« Last Edit: August 29, 2011, 09:27:01 am by SurferTim » Logged

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

Thanks I will try out removing it (and no worries about response time we are all busy)...

Quote
You should be able to put it in the same directory as your code.
Then use
#include "WProgram.h"

When you say "it" do you mean I can just copy the WProgram.h header file into the same directory? I am new to C so is the header file just an interface description and has no need for a class or object file?

Thanks

Jackie
Logged

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

http://code.google.com/p/arduino/wiki/Arduino1

Quote
Renamed WProgram.h to Arduino.h.
Logged

Pages: [1]   Go Up
Jump to: