29 function VS test whether the same macro declared in the two dynamic library header files will be redefined

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.
Insert picture description here

2)
Also add the same macro to the header file of another dynamic library 2 and generate it.
Insert picture description here

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:
Insert picture description here

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.
Insert picture description here

2) Dynamic library 2 adds the same macro.
Insert picture description here

3) Generate the corresponding dynamic library file, and then execute the project.
Insert picture description here

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.

Guess you like

Origin blog.csdn.net/weixin_44517656/article/details/108179811