C2491: 'std::numpunct<_Elem>::id' : definition of dllimport static data member not allowed

前端 未结 1 567
温柔的废话
温柔的废话 2020-12-11 20:12

Given following code,

#include 
#include 

template  void func() {
    std::basic_stringstream out         


        
相关标签:
1条回答
  • 2020-12-11 20:40

    You can't declare methods with

    _declspec(dllimport)
    

    and provide a definition for them.

    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)
    

    The usual way of doing this is:

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

    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.

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

    0 讨论(0)
提交回复
热议问题