0

我正在为基于 CMake 的 Windows、Linux/Unix 构建一个 C++ 库。我在 Windows 上创建了一个共享库(.dll),我想在 Linux / Unix 上使用一个静态库(.a)。

在 Windows 上,我知道如何处理__declspec(dllexport/dllimport)我想要导出的每个函数和类。然后我最近看到了这些文章。(https://blog.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/)我尝试在没有__declspec()库函数的情况下构建 CMakeLists.txt在文章中。

include(GenerateExportHeader)
generate_export_header(mylibrary)

根据文章,为了导出类中的静态成员变量,需要根据现有方法创建导出头,并声明变量如下。

#include <mylibary_export.h>

class MyClass
{
    static mylibrary_EXPORT int GlobalCounter;
    ...
}

该库已成功编译,但尝试GlobalCount在下游项目中引用此变量会导致 LINK 错误。

你对这个问题有想法吗?

4

0 回答 0