1. Determine whether it is debug or release compilation.
If _ debug is defined, it indicates debug compilation; otherwise, it indicates release compilation.
2. Determine whether to perform 32-bit or 64-bit compilation.
In Win32 configuration, _ Win32 is defined, and _ win64 is not defined. In x64 configuration, both are defined. In VC, _ Win32 must be defined.
Therefore, Win32/_ Win32 can be used to determine whether a Windows system (for cross-platform programs), while _ win64 can be used to determine whether the compiling environment is x86 or x64. A table is attached:
Constant \ define predefined options windows. h VC Compiler
Win32 Win32 √ (minwindef. h) ×
_ Win32 ××√
_ Win64 ×× x64
Finally, the following example code is provided to link the corresponding static library with conditions based on the Compilation conditions. It is actually the use of some macro definition statements:
# Include "JSON/JSON. H"
# Ifdef _ debug
# Ifndef _ win64
# Pragma comment (Lib, "JSON/json_mtd.lib ")
# Else
# Pragma comment (Lib, "JSON/json_mtd_x64.lib ")
# Endif
# Else
# Ifndef _ win64
# Pragma comment (Lib, "JSON/json_mt.lib ")
# Else
# Pragma comment (Lib, "JSON/json_mt_x64.lib ")
# Endif
# Endif
# Ifndef _ win64
Afx_msg void ontimer (uint nidevent );
# Else if
Afx_msg void ontimer (uint_ptr nidevent );
# Endif