gpt4 book ai didi

c++ - CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 不覆盖全局变量

转载 作者:行者123 更新时间:2023-11-28 04:25:00 25 4
gpt4 key购买 nike

将 CMake 下的 C++ 库移植到 Windows。

  • 选项 1:使用 __declspec(dllexport) 修饰 API。
  • 选项 2:设置(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

我们选择选项 2,因为它看起来更容易,并且完整地保留了我们的资源。工作起来很神奇:我们的应用程序编译并与库 dll 链接。

但是,它只确保类和函数的导出。导出全局变量需要做什么?喜欢在:

lib_source.cpp:
int my_secret;

app.cpp:
extern int my_secret;

最佳答案

For global data symbols, __declspec(dllimport) must still be used when compiling against the code in the .dll.

来源:https://cmake.org/cmake/help/latest/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html

关于c++ - CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 不覆盖全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54560832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com