Loading...
Pages: 1 [2]   Go Down
Author Topic: Problem with conditional #include  (Read 519 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 119
Posts: 10165
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I was thinking compiler...

Code:
MCP79412RTC\MCP79412RTC.cpp.o:C:\Documents and Settings\Jack\My Documents\arduino\sketchbook\libraries\MCP79412RTC/MCP79412RTC.cpp:551: multiple definition of `RTC'
DS1307RTC\DS1307RTC.cpp.o:C:\Documents and Settings\Jack\My Documents\arduino\sketchbook\libraries\DS1307RTC/DS1307RTC.cpp:112: first defined here

Nope.  Dot-oh files are the domain of the linker.

In my case, I use // comments to "remove" one of the libraries.  It's horribly annoying but it works.
Logged

Offline Offline
Sr. Member
****
Karma: 11
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is a well documented and well known failing of the Arduino IDE preprocessor. It doesn't respect (or simply ignores) the preprocessor conditionals, and will aggressively match any line starting with #include for a library inclusion.

It's been reported as a problem for years. Like many other problems with the IDE preprocessor, Team Arduino don't think it's a big deal, apparently, so it's not going to be fixed.

Actually, this isn't _entirely_ true, on reflection. The _one time_ that the conditional #include does work is if you say

#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

When I first saw this , I thought "Yay! They finally fixed the IDE preprocessor to respect conditional #include!"

But no. They just fixed it for this one special case for _their_ convenience. The rest of the plebs can just suffer. LOL.

It's "design decisions" like these that earn them the opprobrium amongst serious software developers they so justly deserve. Disgraceful, really.

They did do some important fixes in 0023->1.0, however, like renaming the .pde files to become .ino, and "WProgram.h" to become "Arduino.h". All an exercise in branding, of course. Which shows where their priorities lie, I suppose.

There. My spleen feels a little better now.

« Last Edit: November 25, 2012, 11:31:18 pm by pico » Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 43
Posts: 2510
"We're a proud service of the Lost Electricity Reclamation Agency"
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nope.  Dot-oh files are the domain of the linker.

Right, right, makes sense.

Quote
In my case, I use // comments to "remove" one of the libraries.  It's horribly annoying but it works.

Probably will go the same route. Agree it's annoying! smiley-yell

Thanks!
Logged

Get the infamous "One Million Ohms" board at tINDIE.com: http://tinyurl.com/BuyMohms

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 43
Posts: 2510
"We're a proud service of the Lost Electricity Reclamation Agency"
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually, this isn't _entirely_ true, on reflection. The _one time_ that the conditional #include does work is if you say

#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

When I first saw this , I thought "Yay! They finally fixed the IDE preprocessor to respect conditional #include!"

But no. They just fixed it for this one special case for _their_ convenience. The rest of the plebs can just suffer. LOL.

Wow, that is terrible. I have of course used that very construct. Maybe that was part of my confusion, I just couldn't see what was wrong.

Quote
It's "design decisions" like these that earn them the opprobrium amongst serious software developers they so justly deserve. Disgraceful, really.

On the one hand I get making things easy for beginners, but when it results in departure from well established standards and undesirable behavior that is not easy to fix, I have to draw the line.

Quote
They did do some important fixes in 0023->1.0, however, like renaming the .pde files to become .ino, and "WProgram.h" to become "Arduino.h". All an exercise in branding, of course. Which shows where their priorities lie, I suppose.

I've noticed how much better my code runs with these "fixes" smiley-razz

Quote
There. My spleen feels a little better now.
smiley-grin
Logged

Get the infamous "One Million Ohms" board at tINDIE.com: http://tinyurl.com/BuyMohms

Offline Offline
Edison Member
*
Karma: 15
Posts: 1009
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is a well documented and well known failing of the Arduino IDE preprocessor. It doesn't respect (or simply ignores) the preprocessor conditionals, and will aggressively match any line starting with #include for a library inclusion.

It's been reported as a problem for years. Like many other problems with the IDE preprocessor, Team Arduino don't think it's a big deal, apparently, so it's not going to be fixed.

Actually, this isn't _entirely_ true, on reflection. The _one time_ that the conditional #include does work is if you say

#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

When I first saw this , I thought "Yay! They finally fixed the IDE preprocessor to respect conditional #include!"

But no. They just fixed it for this one special case for _their_ convenience. The rest of the plebs can just suffer. LOL.

Er. No. The gcc preprocessor actually includes the file, which has always worked correctly with the conditionals. The IDE just figures out what -I (minus-eye) switches to use so the preprocessor can figure out where "Wire.h" is on your computer (which doesn't screw up anthing when it fails) and also which .cpp files to compile and link in (which in your case can screw things up). It doesn't need to do either of those for WProgram.h or Arduino.h (although I guess it does have built-in rules to deal with the files in the arduino/hardware/cores/arduino directory)
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 219
Posts: 13896
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's the problem ...

The compile isn't done in your sketch directory. All the files in the sketch are copied to a temporary directory, along with any files mentioned in #include in the main sketch.

This is why you have to put (say) "#include <Wire.h>" in the main sketch, even if only a library uses it.

Now since the IDE doesn't honour preprocessor directives (and to be honest, it would probably be hard to) it copies all the files you mention to this temporary directory, and compiles them.

Hence the error message:

Code:
MCP79412RTC\MCP79412RTC.cpp.o:C:\Documents and Settings\Jack\My Documents\arduino\sketchbook\libraries\MCP79412RTC/MCP79412RTC.cpp:551: multiple definition of `RTC'
DS1307RTC\DS1307RTC.cpp.o:C:\Documents and Settings\Jack\My Documents\arduino\sketchbook\libraries\DS1307RTC/DS1307RTC.cpp:112: first defined here

You'll notice that is a linker error message.

I don't know there is a way around it. I was tempted to suggest you put the conditional includes into a .cpp file (where they would be honoured) but then neither of the included files would be copied, and you would get missing symbol messages.
Logged


Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 219
Posts: 13896
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe if you somehow made your own .h file (which gets copied into the temporary directory) and inside that you have the conditional directives which then include the files you really want, with a full pathname.
Logged


Pages: 1 [2]   Go Up
Print
 
Jump to: