CMake 添加了 -Dlibname_EXPORTS编译定义



CMake 在编译目标时会自动将以下编译定义添加到所有源代码文件中:

-Dlibname_EXPORTS

为什么要这样做,如何禁用它?

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();

可以通过将目标的 DEFINE_SYMBOL 属性设置为空来禁用它。

# disable the <libname>_EXPORTS
set_target_properties(sharedlib
  PROPERTIES
  DEFINE_SYMBOL ""
  )

参考

  • http://www.cmake.org/cmake/help/v3.0/prop_tgt/DEFINE_SYMBOL.html

最新更新