c++ - How to define a macro in a header file from the makefile -


i have written own header file checking assertions myassert.h, similar assert.h header , include in file, project_file.h. have ndebug macro when defined before inclusion of myassert.h, disables checking of assertions. however, dont want turn off assertion checking defining ndebug @ beginning of project_file.h. instead want have flag in makefile during compilation, user can set flag automatically disable/enable assertions checking feature. file project_file.h 1 file in huge project. can please tell me how this? have checked other answers did not quite understand how make work.

thank much.

what you're looking called preprocessor definition. should pass -dndebug gcc options.

for more information -d option: http://gcc.gnu.org/onlinedocs/gcc/preprocessor-options.html

there 2 ways use -d: -d name, -d name=definition.

then in code use:

#ifndef ndebug     // ... #endif 

or

#if ndebug!=0     // ... #endif 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -