c++ - Compiler acts as if a preprocessor directive isn't defined -
i have header file , cpp file (error.h, error.cpp). cpp file performs check on preprocessor directive fails.
error.h:
/* optional macros: ae_exit_at_error ae_console_write_at_error */ #pragma once extern void aeerror(const char *str, int code=1); extern void aeassert(bool b, const char *failstr = "assertion failed");
error.cpp:
#include "error.h" #include <stdexcept> #ifdef ae_console_write_at_error #include <iostream> #endif void aeerror(const char *str, int code) { #ifdef ae_console_write_at_error std::cout << str << std::endl; #endif throw std::runtime_error(str); #ifdef ae_exit_at_error std::exit(code); #endif } void aeassert(bool b, const char *failstr) { if(!b) aeerror(failstr); }
main.cpp:
//define both macros: #define ae_console_write_at_error #define ae_exit_at_error #include "error.h" //rest of code //...
both std::cout << str << std::endl;
, std::exit(code);
don't compiled (i checked "manually", although marked gray ide, vs2010).
what might cause of this?
main.cpp
, error.cpp
different translation units. define macro main.cpp
, not error.cpp
.
you should either put #define
directives in header file included both .cpp files, or define these macros in project settings/makefile.
Comments
Post a Comment