C++ will ifdef block cause ABI compatibility issues?

  abi, c++, compilation, gcc

Let’s say we’re building a library mylib and below is the header file

# mylib.h

// some include 

#include <dependent_library_a>
#include <dependent_library_b>

class MyLib {

void feature_xxx_related_function(type_in_dependent_library_a param1, type_in_dependent_library_b param2);


I want to use the ENABLE_XXX_FEATURE definition to control the visibility of some code blocks. If user doesn’t need feature xxx, then he won’t define ENABLE_XXX_FEATURE and thus he won’t see #include <dependent_library_a>and #include <dependent_library_b>, and he doesn’t have to install those libraries.

The code block inside ifdef involves some very heavy dependencies and most user doesn’t need them at all and obviously, I don’t want them to install those dependencies.

My only concern is the ABI compatibility:

  • when I compile mylib I will enable the ENABLE_XXX_FEATURE and the output .so file will contain all the things inside ifdef block.
  • when user include my header without defining ENABLE_XXX_FEATURE, he will see a different definition of class MyLib, and when he try to link my mylib.so will this cause any ABI compatibility issues?

Source: Windows Questions C++