Go Down

Topic: Cannot Find WProgram.h (differant) (Read 6209 times) previous topic - next topic

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: [Select]

/*
  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: [Select]

#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: [Select]

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: [Select]

     [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!

baum

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

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

Changed to...
Code: [Select]
#include <WProgram.h>
#include "Morse.h"

Also tried
Code: [Select]
#include <WProgram.h>
#include <Morse.h>


Response

Code: [Select]
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: [Select]
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?

baum

What happens if you don't include it?

SurferTim

#4
Aug 25, 2011, 12:12 pm Last Edit: Aug 25, 2011, 01:28 pm by SurferTim Reason: 1
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: [Select]
void Morse::Morse(int pin)
{
 pinMode(pin, OUTPUT);
 _pin = pin;
}


Change it in the Morse.h file also.
Code: [Select]
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: [Select]
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.

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?

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


Code: [Select]
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

SurferTim

#7
Aug 26, 2011, 11:35 am Last Edit: Aug 26, 2011, 11:55 am by SurferTim Reason: 1
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: [Select]
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: [Select]
#include <WProgram.h>
#include "WProgram.h"

I do not need either of those to compile that code in the Arduino IDE.

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?

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?

Tried this... no dice still...

Code: [Select]
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.

SurferTim

#11
Aug 29, 2011, 04:08 pm Last Edit: Aug 29, 2011, 04:27 pm by SurferTim Reason: 1
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.


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

anon10500

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

Quote
Renamed WProgram.h to Arduino.h.

Go Up