29 function VS test whether the same macro declared in the two dynamic library header files will be redefined
1 Test in the header file of the dynamic library
1)
First add a macro definition to the header file of a dynamic library. Then generate the lib and dll of the dynamic library.
2)
Also add the same macro to the header file of another dynamic library 2 and generate it.
3)
Include the header files and lib, dll of the two dynamic libraries into the current project according to the practice when creating the dynamic library to prevent compilation errors. Click to generate as follows:
It can be seen from the result that defining the same macro in the header files of the two dynamic libraries will not cause the macro to be redefined. You can understand it in terms of namespaces, that is, they are the same thing with variable names in two different namespaces.
2 Test in the cpp file of the
dynamic library 1) Add macros to the dynamic library 1.
2) Dynamic library 2 adds the same macro.
3) Generate the corresponding dynamic library file, and then execute the project.
As you can see from the result, the macro you defined in the cpp file will not be imported into the dynamic library at all, so the result shows that the SDK_ macro is not defined.
That is to say: if you want to call the macro of the dynamic library released by others in your project, you must write it in the header file when encapsulating it, otherwise you cannot call it.