且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C2491:“std::numpunct<_Elem>::id":不允许定义 dllimport 静态数据成员

更新时间:2023-11-09 22:03:34

你不能用

_declspec(dllimport)

并为它们提供定义.

限定符告诉编译器该函数是从与您现在正在编译的库不同的库中导入的,因此为其提供定义是没有意义的.

The qualifier tells the compiler that the function is imported from a different library than the one you are compiling now, so it wouldn't make sense to provide a definition for it.

当包含标题时,限定符应该是

When including the header, the qualifier should be

_declspec(dllimport)

当你编译提供方法定义的模块时,它应该是:

and when you are compiling the module that provides a definition for the method it should be:

_declspec(dllexport)

通常的做法是:

#ifdef CURRENT_MODULE
#define DLLIMPORTEXPORT _declspec(dllexport)
#else
#define DLLIMPORTEXPORT _declspec(dllimport)
#endif

define CURRENT_MODULE 仅在包含定义的模块中定义,因此在编译该模块时会导出该方法.包含标题的所有其他模块都没有定义 CURRENT_MODULE,该函数将被导入.

The define CURRENT_MODULE is only defined in the module that contains the definitions, so when compiling that module the method is exported. All other modules that include the header don't have CURRENT_MODULE defined and the function will be imported.

我猜您的指令 - _declspecimport - 与此类似.

I'm guessing your directive - _declspecimport - is similar to this.