An example of a cpp file that I want to compile differently depending whether it is a program or a library.

Dependencies:   mbed

Committer:
glansberry
Date:
Wed May 06 12:10:43 2015 +0000
Revision:
0:e41c1aad3627
initial checkin

Who changed what in which revision?

UserRevisionLine numberNew contents of line
glansberry 0:e41c1aad3627 1 #include "mbed.h"
glansberry 0:e41c1aad3627 2
glansberry 0:e41c1aad3627 3 class LED_TEST:public DigitalOut{
glansberry 0:e41c1aad3627 4 public:
glansberry 0:e41c1aad3627 5 LED_TEST(PinName pin):DigitalOut(pin) {};
glansberry 0:e41c1aad3627 6
glansberry 0:e41c1aad3627 7 void TurnOn() {write(1);}
glansberry 0:e41c1aad3627 8 void TurnOff() {write(0);}
glansberry 0:e41c1aad3627 9 };
glansberry 0:e41c1aad3627 10
glansberry 0:e41c1aad3627 11 #ifdef __IN_A_PROGRAM //if I'm compiling as a program then I want to create this main for testing.
glansberry 0:e41c1aad3627 12 //if I'm compiling as a library I do not want the main to prevent linker problems
glansberry 0:e41c1aad3627 13 int main(void)
glansberry 0:e41c1aad3627 14 {
glansberry 0:e41c1aad3627 15 LED_TEST lt(LED1);
glansberry 0:e41c1aad3627 16 while (1)
glansberry 0:e41c1aad3627 17 {
glansberry 0:e41c1aad3627 18 lt.TurnOn();
glansberry 0:e41c1aad3627 19 wait(1);
glansberry 0:e41c1aad3627 20 lt.TurnOff();
glansberry 0:e41c1aad3627 21 wait(1);
glansberry 0:e41c1aad3627 22 }
glansberry 0:e41c1aad3627 23 }
glansberry 0:e41c1aad3627 24 #endif