我正在尝试理解libspatialindex源代码。作为 C++ 的新手,我很难理解宏的概念。该库的 C API 包装器sidx_api.cc直接和间接地包括许多头文件,其中两个似乎定义了相同的宏,涉及与动态库的接口,没有“undef”:
45 #if (defined _WIN32 || defined _WIN64 || defined WIN32 || defined WIN64) && !defined __GNUC__
46 #ifdef SIDX_DLL_EXPORT
47 #define SIDX_DLL __declspec(dllexport)
48 #else
49 #define SIDX_DLL __declspec(dllimport)
50 #endif
51
52 // Nuke this annoying warning. See http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html
53 #pragma warning( disable: 4251 )
54
55 #else
56 #define SIDX_DLL
57 #endif
29 #pragma once
30
31 #ifndef SIDX_C_DLL
32 #if defined(_MSC_VER)
33 # define SIDX_C_DLL __declspec(dllexport)
34 # define SIDX_DLL __declspec(dllexport)
35 #else
36 # if defined(USE_GCC_VISIBILITY_FLAG)
37 # define SIDX_C_DLL __attribute__ ((visibility("default")))
38 # define SIDX_DLL __attribute__ ((visibility("default")))
39 # else
40 # define SIDX_C_DLL
41 # define SIDX_DLL
42 # endif
43 #endif
44 #endif