I have some macros like, #define dosomething(x) something(x)
and it is compiled into a dll. Will I have that macro in that lib created by the build?

- 642
- 1
- 7
- 19
3 Answers
No.
Macros aren't even visible to the compiler. They get replaced by their substitution text during preprocessing, which happens at the very beginning. Macros are dumb, they know nothing about you or your motives. They don't even know what language you're writing. Beware!

- 464,522
- 92
- 875
- 1,084
No.
Macros are just a (not so) elaborated copy pasting device at the source code level. They are expanded before compilation, and the compiler isn't aware of their existence.
If you want the dosomething
symbol to be exported in your library, you have to declare it as a function.

- 55,948
- 11
- 128
- 197
Macros are used and processed by pre-processor only. They aren't used by compiler and not at all known by the linker. So, the answer is NO. Macros are not exported.
What do you need? Can't you just #include
given header file?

- 18,086
- 12
- 59
- 105
-
I have a set of code that is compiled into a library. Now, Am trying to create a COM interface for that set of code , so I included that lib in the linker properties of the ATL project. While building, the ATL project throws linker error of `LNK2019 undefined external symbols`in places where I have these macros. So, Is there a way to solve this problem or should I remove the macro and redefine them as standard functions? – Venkatesh Kumar Aug 12 '11 at 08:21
-
These are probably functions or classes (or global variables), but not macros. Can you give some code, more information? – Ajay Aug 12 '11 at 08:23
-
The macro `#define OnAssertionFailure(_expr,_action)\ if(!(_expr))\ {\ AssertionBreak(__LINE__,Stringifier(_expr),__FILE__);\ _action;\ }` – Venkatesh Kumar Aug 12 '11 at 08:32
-
The `LNK2019` error states that `AssertionBreak` external symbol is not defined. – Venkatesh Kumar Aug 12 '11 at 08:37
-
@Venkatesh Kumar: `AssertionBreak` is _not_ a macro! `OnAssertionFailure` is, but that doesn't appear in the dll because it's been replaced by `AssertionBreak` – MSalters Aug 12 '11 at 08:42
-
Therefore you need to find out where `AssertionBreak` is defined and include it in compilation and/or linking. – Ajay Aug 12 '11 at 08:43