Toolchain problem: compiling with alternative libraries

This is really not specific to ethernet, i think its a toolchain (IDE) issue (or rather an issue on my side understanding the IDE). It just happens with ethernet:

I have written a sketch that i want to compile against different arduino types. I managed to get it to work to compile for Yun and for Erduino Ethernet automatically. Set board type in IDE, Arduino IDE will include some different #define, i conditionally have code against that.

Now the problem is to make it compile for Arduino Eth (requiring Ethrernet library) vs. Arduino Leonardo Eth (requiring Ethernet2 library). Simple sketch:

#if NUM_DIGITAL_PINS == 30
#define NETWORK_W5500
#endif

#ifdef NETWORK_W5500
#include "Ethernet2.h"
#include "utility/w5500.h"
#else
#include "Ethernet.h"
#include "utility/w5100.h"
#endif

Forget the kludgy rule to select which board it is: The problem is that compiling this sketch leads to duplicate definitions, eg:

Ethernet/Dhcp.cpp.o: In function `DhcpClass::reset_DHCP_lease()':
/Applications/Internet/Arduino-1.7.7.app/Contents/Java/libraries/Ethernet/src/Dhcp.cpp:32: multiple definition of `DhcpClass::reset_DHCP_lease()'
Ethernet2/Dhcp.cpp.o:/Applications/Internet/Arduino-1.7.7.app/Contents/Java/libraries/Ethernet2/src/Dhcp.cpp:32: first defined here
Ethernet/Dhcp.cpp.o: In function `DhcpClass::reset_DHCP_lease()':
...
collect2: error: ld returned 1 exit status
Error compiling.

It seems as if the IDE actually tries to grep all includes from the .pde files even those not really included and then links against the libraries.

Lol, I just opened an issue for this... It is already fixed in 1.6.6

Cheers,
/dev

could you explain a bit please ?

URL/num of the issue so i can look it up ?

How does the IDE decide which which of the two libraries to link against to fix this ?

te36:
could you explain a bit please ?

URL/num of the issue so i can look it up ?

Issue here.

te36:
How does the IDE decide which which of the two libraries to link against to fix this ?

It can't. That's why it's an error: Multiple define. Either comment out the offending include as I showed in the issue, or upgrade to 1.6.6.

Cheers,
/dev