views:

468

answers:

2

I'm working in an embedded system (RTXC) where I need to disable the debugger functionality which is enabled through a #define command. However, when I change the #define to undefine, compilation goes off fine, but when the linker runs, it encounters an error about a symbol not existing that belongs to the debug code (which should have been taken care of by the debugger variable not being defined). Is there any way for Make to ensure that a preprocessor variable does not get defined or stays undefined ?

A: 

No. You will need to fix the bug in your code.

More specifically, there is something that is referencing the debug side of things outside of an #ifdef. Make won't be able to help you there.

Another possibility is that you have a .o or something left over from a previous build; you might want to try cleaning the build tree.

retracile
Unfortunately I've done both of those and the linking problem still persists. I've checked every usage of the variable and guaranteed that they're all enclosed within #ifdef blocks, and I've ensure that every last a, o, and so built by the project is cleared out of the build directory (and / or built fresh). Thank you for your response nonetheless
Alex Marshall
@Alex Marshall: Does your compiler not tell you where the unsatisfied reference is coming from (first location, usually)? Have you run 'nm -g' on object files or libraries to locate them?
Jonathan Leffler
@Jonathan Leffler: I'm using an embedded OS, RTXC. The compiler tells me that the problem is coming from one of the kernel libraries : librtxc.a. 'nm -g librtxc.a' tells me that the reference is in rtxcasm.o. The libraries are being recompiled from scratch with the CBUG variable being undefined, yet somehow a reference to _isrcnt remains. I've checked all the references to isrcnt, and they're all properly enclosed with #ifdef CBUG tags, so I can see no reason why any _isrcnt symbol should be compiled into the rtxcasm.o object file. Incidentially, thank you for 'nm -g', I was unaware of it
Alex Marshall
+1  A: 

The answer to your question is no, Make can't absolutely prevent a variable from being defined by, say, a #define expression in the code.

You seem to have an elusive problem. It could be a bug in your Makefiles, a misspelled directive, a bad macro (if you'll pardon the tautology) or something trivial. I'd suggest burning the forest: cut out everything until the problem stops, then see where it was hiding. If you get down to HelloWorld and the problem persists, let us know.

Beta