Society of Robots - Robot Forum

Software => Software => Topic started by: madsci1016 on August 14, 2010, 09:50:11 AM

Title: Help with pre-processor directives
Post by: madsci1016 on August 14, 2010, 09:50:11 AM
I have several

#ifdef DEBUG

statements in a library file. I'd like to be able to activate those from my main c file without editing the library file. Is there a way to do that? I can't get it to work.

So the Main c file has

Code: [Select]
#define DEBUG
#include <library.h>

where library.h has all the ifdef statements in them. But this won't work, at least in the Arduino IDE. If i define DEBUG in the library header fille, then they all work.

Title: Re: Help with pre-processor directives
Post by: madsci1016 on August 14, 2010, 04:00:08 PM
Nevermind, i'm pretty sure I can't do what I want.
Title: Re: Help with pre-processor directives
Post by: Webbot on August 14, 2010, 10:23:05 PM
pre-processor directives only work at the point of generating the code.

So if the library is precompiled already then the '#defines' are  now irrelevant.

Other alternative is build two libs - one with debug, one without. Then the user can choose which to link with. Only trouble is it means 'debug everything' or 'nothing'
Title: Re: Help with pre-processor directives
Post by: madsci1016 on August 15, 2010, 08:40:13 AM
So if the library is precompiled already then the '#defines' are  now irrelevant.

Well, the library is not pre-compiled, like the .a files of webbotlib, unless you mean that the compiler first compiles any included source files before compiling the main .c file.
Title: Re: Help with pre-processor directives
Post by: billhowl on August 15, 2010, 09:24:27 AM
For arduino library, you need to delete the .o file in that library then you will able to get compiler re-compile that library.
Title: Re: Help with pre-processor directives
Post by: madsci1016 on August 15, 2010, 11:53:04 AM
I'll try that Bill, but i was making changes to the library .cpp file externally using notepad++ and just hitting compile in the Arduino IDE seemed to compile with any changes made, so i think it was running a fresh compile every time instead of just linking the binary.