在简单编译目标时,CMake会自动将以下编译定义添加到所有源代码文件中:
-Dlibname_EXPORTS
为什么要这样做,如何禁用它?
答案 0 :(得分:10)
cmake仅为共享库添加<libname>_EXPORTS
个宏。在Windows DLL中导出API时非常有用。
#if defined(_WINDOWS) && defined(testlib_EXPORTS)
# define API_DLL extern "C" __declspec(dllexport)
#else
# define API_DLL
#endif
API_DLL void foo();
可以通过将target的DEFINE_SYMBOL
属性设置为空来禁用它。
# disable the <libname>_EXPORTS
set_target_properties(sharedlib
PROPERTIES
DEFINE_SYMBOL ""
)
<强>参考强>