CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS不涵盖全局变量 [英] CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS does not cover global variables
本文介绍了CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS不涵盖全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在CMake下将C ++库移植到Windows。
Porting a C++ library, under CMake, to Windows.
- 选项1:使用
__ declspec装饰API (dllexport)
。 - 选项2:
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
。
- Option 1: Decorate the API with
__declspec(dllexport)
. - Option 2:
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
.
我们选择选项2,因为这似乎容易得多,并且使我们的资源完整无缺。
的工作原理就像是一种魅力:我们的应用程序可以编译并与库dll链接。
We go for option 2, since it seems much easier, and leaves our sources intact. Works like a charm: our application compiles and gets linked with the library dll.
但是,它只能确保导出类和函数。导出全局变量需要做什么?像这样:
However, it ensures only the export of classes and functions. What needs to be done to export global variables? Like in:
lib_source.cpp:
int my_secret;
app.cpp:
extern int my_secret;
推荐答案
用于全局数据符号,对.dll中的代码进行编译时,仍必须使用
__ declspec(dllimport)
。
src: https://cmake.org/cmake/help /latest/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html
这篇关于CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS不涵盖全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文