Pages: [1]   Go Down
Author Topic: Have to include wiring_private.h in all .h files? Rant time!  (Read 878 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Come on guys.  Really?  I've played with AVRs off an on over the years, I'm by no means an expert.  But I created two .h files with their corresponding .cpps and include them in my main routine along with wiring.h and WProgram.h and use this IDE (I didn't have an Arduino when I started this, now I do)

http://code.google.com/p/avr-project-ide/

and it happily compiles this code and is quite runnable.  I move over to the sketch world and this very basic concept is fundamentally broken with the compiler spewing

 "ISO C++ forbids declaration of ...."

which a google search reveals to be a very popular type of error to get out of the Arduino software/compiler?  Look, I get that the entire concept is so the average hobbyist isn't going to get into the weeds with some of the things I've done with my code, but to break something so basic as a #include?
« Last Edit: January 07, 2012, 05:29:31 pm by ElectricallyPerfect » Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 486
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

its supposed to look like #include <EEPROM.h> not #include "EEPROM.h" for example.

post code, may help figure it out...
Logged

http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49080
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the compiler can't include the header file, it will tell you that in no uncertain terms.

If it is able to, and the contents are garbage, it will tell you different things.

So, it appears as though the IDE was able to include the file, but that it is garbage. So, what header file are you talking about, and what is in it?
Logged

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

I don't think you guys noticed this point:

Quote
and it happily compiles this code and is quite runnable

This isn't an Arduino supported library.  It's extra_file1.h with a couple structs and function prototypes along with extra_file1.cpp and extra_file2.h and extra_file2.cpp.  I could have shoved all of this into one large main.cpp as I didn't make classes yet (getting interrupts to work properly with classes was a pain at the time).  The point is, avr-gcc has no problem with this very standard #include "extra_file1.h" convention and finds and links all the functions without trouble.  Why is this broken with Arduino?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49080
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Why is this broken with Arduino?
It is not broken on the Arduino. The Arduino compiler found and included the header file. If it hadn't, it would not be complaining that it can't compile what is in the header file.

Quote
This isn't an Arduino supported library.
Then why are you trying to use it on an Arduino?

Arduino-supported and Arduino-compatible aren't the same thing, but you really need to quit ranting and show us what is in these mysterious header files.
Logged

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

This is the top of yair_arduino

Code:
//
/*****************************************
*
*
******************************************/

#include "yair_send.h"
#include "yair_receive.h"
#include "HardwareSerial.h"
#include <avr/pgmspace.h>

This is the top part of yair_send.h:

Code:
#ifndef yair_send_h
#define yair_send_h


struct remoteSpecifics {
unsigned int commandMark;
unsigned int spaceZero;
unsigned int spaceOne;
unsigned int startMark;
unsigned int startSpace;
unsigned int stopSpace;
unsigned int pulsesInCode;
unsigned int tolerance;
//String nameText;
};

struct infraredBit {
unsigned int mark;
unsigned int space;
};

struct commandSwitch {
byte * convertFrom;
byte * convertTo;
byte convertedBytes;
byte outgoingRemote;
};

It pukes on the first byte pointers:

In file included from yair_arduino.cpp:7:
yair_send.h:26: error: ISO C++ forbids declaration of 'byte' with no type
yair_send.h:26: error: expected ';' before '*' token
yair_send.h:27: error: ISO C++ forbids declaration of 'byte' with no type
yair_send.h:27: error: expected ';' before '*' token
yair_send.h:28: error: 'byte' does not name a type
yair_send.h:29: error: 'byte' does not name a type


Quote
Then why are you trying to use it on an Arduino?
I hope to release the code/hardware for people to use, it's Yet Another IR Remote but you can actually use it to send and receive commands at the same time, unlike the majority of the IR projects I've found, including the one bundled with the IDE.

« Last Edit: January 07, 2012, 03:06:18 pm by ElectricallyPerfect » Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1615
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This:
Code:
struct remoteSpecifics {
unsigned int commandMark;
unsigned int spaceZero;
unsigned int spaceOne;
unsigned int startMark;
unsigned int startSpace;
unsigned int stopSpace;
unsigned int pulsesInCode;
unsigned int tolerance;
//String nameText;
};

struct infraredBit {
unsigned int mark;
unsigned int space;
};

struct commandSwitch {
byte * convertFrom;
byte * convertTo;
byte convertedBytes;
byte outgoingRemote;
};

void setup()
{
}

void loop()
{
}
compiles without error with V1.0, so it would appear that you are doing something wrong.

Pete
Logged

Where are the Nick Gammons of yesteryear?

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49080
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This is the top of yair_arduino
yair_arduino.what?

Where is the rest of it?

Quote
This is the top part of yair_send.h:
Where is the rest of it?

Do you want help, or do you just want to rant?

One thing to note is that byte is not a native type. It is defined in wiring,h, which you may not be including.
« Last Edit: January 07, 2012, 03:30:02 pm by PaulS » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 301
Posts: 26242
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Whilst I can't disagree that this is a rant, it isn't a problem with the #include mechanism.
@OP please post all code, and change the topic title
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Edison Member
*
Karma: 48
Posts: 1615
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmmm. There does seem to be something odd here.
I set up a junk sketch with yair_send.h:
Code:
#ifndef yair_send_h
#define yair_send_h


struct remoteSpecifics {
unsigned int commandMark;
unsigned int spaceZero;
unsigned int spaceOne;
unsigned int startMark;
unsigned int startSpace;
unsigned int stopSpace;
unsigned int pulsesInCode;
unsigned int tolerance;
//String nameText;
};

struct infraredBit {
unsigned int mark;
unsigned int space;
};

struct commandSwitch {
byte * convertFrom;
byte * convertTo;
byte convertedBytes;
byte outgoingRemote;
};
#endif

and junk.ino:
Code:
#include "yair_send.h"
void setup()
{
}

void loop()
{
}

and it fails as the OP says. Strange that the code in my previous post works and this doesn't.

AHAhhhhhhhhhhhhhhhhhhhhhhhhhhhhh! Got it.

This has also caused me grief (I posted about it several weeks ago).

The preprocessor includes all sorts of stuff to support the sketch. The problem is that when it does this, it puts it just before the first "executable" statement in the code. In the example above it inserted it just before "void setup()" which means that the included files which define "byte" occur AFTER the include of yair_send.h. My previous example (without the include) must have worked because it treated the struct, which ends in a semicolon, as "executable".

The fix is to put a "char junk;" statement in front of your includes. E.G. my junk project compiles if it starts with:
Code:
char junk;
#include "yair_send.h"
I presume you could even put a junk struct at the front if you wished.


Pete
Logged

Where are the Nick Gammons of yesteryear?

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

Quote
It is defined in wiring,h, which you may not be including.

It seems that it is now named wiring_private.h.  Adding that to yair_arduino.cpp and both .h files fixed everything.  I guess the IDE I included above does a better job during the make process as I only need wiring.h (now wiring_private) included in yair_arduino.cpp



Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1615
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My fix (see previous post) is a better solution since it only requires one additional line in your sketch.
I would, however, change my fix slightly. As I described it, it requires one byte of SRAM space. A better solution is to put a dummy struct at the front of the file. This way the preprocessor puts its includes where you need them and the fix doesn't require any ram at all.
Just put something like this this as the first line of every sketch you ever write:
Code:
struct useless_junk { char whatever; };

Pete
Logged

Where are the Nick Gammons of yesteryear?

Pages: [1]   Go Up
Jump to: