go_away

Author Topic: Help with pre-processor directives  (Read 801 times)

0 Members and 1 Guest are viewing this topic.

Offline madsci1016Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Help with pre-processor directives
« 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.


Offline madsci1016Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Re: Help with pre-processor directives
« Reply #1 on: August 14, 2010, 04:00:08 PM »
Nevermind, i'm pretty sure I can't do what I want.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,121
  • Helpful? 108
Re: Help with pre-processor directives
« Reply #2 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'
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline madsci1016Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Re: Help with pre-processor directives
« Reply #3 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.

Offline billhowl

  • Supreme Robot
  • *****
  • Posts: 375
  • Helpful? 32
  • Your success is in your hands.
Re: Help with pre-processor directives
« Reply #4 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.

Offline madsci1016Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Re: Help with pre-processor directives
« Reply #5 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.

 


Get Your Ad Here