Assuming I have these two files:
header.h
class DLL ExportClass{ public: ExportClass(); static int test; };
Source.cpp
#ifdef EXPORT #define DLL __declspec(dllexport) #else #define DLL __declspec(dllimport) #endif #include "Header.h" int ExportClass::test = 0; ExportClass::ExportClass(){ }
And I will not determine EXPORT(for importing an already exported class with a member static) why I get these warnings:
EXPORT
static
1>source.cpp(11): warning C4273: 'test' : inconsistent dll linkage 1> header.h(4) : see previous definition of 'public: static int ExportClass::test' 1>source.cpp(13): warning C4273: 'ExportClass::ExportClass' : inconsistent dll linkage 1> header.h(3) : see previous definition of '{ctor}'
And this error:
1>source.cpp(11): error C2491: 'ExportClass::test' : definition of dllimport static data member not allowed
If I determine EXPORT, it works. I kind of understand the warnings, but I thought that the static variable and ctor could be ignored by the compiler, because the whole class is declared as __declspec(dllimport)anyway. I want to use the same code base for __declspec(dllexport)and __declspec(dllimport), but it looks like the stll compiler is trying to identify these characters, marked as __declspec(dllexport)in their declaration. What is common practice to solve this problem?
__declspec(dllimport)
__declspec(dllexport)
, . __declspec (dllimport) , , , . , , , .
C4273 , , , . , , - DLL. , . C4273 - 1, " ". , , . , , , , , DLL. , .
. . , - , , , , . , . , C2491 .
, , , , , .
- :
4 5 , :
Win32, Project2
:
#include "Project1.h" #pragma comment(lib, "Project1.lib") int _tmain(int argc, _TCHAR* argv[]) { ExportClass pClass; return 0; }
, , DLL LIB, .
, , DLL/LIB , ?
Source: https://habr.com/ru/post/1568211/More articles:How to update div outside bootstrap modal - twitter-bootstrapCan a spout or bolt access the identifier by which it is known in the topology? - apache-stormMsBuild ClCompile output format - msbuildruby 2.1 rails 4 sunspots solr tests fail in a set, but pass individually - ruby | fooobar.comUse string as filter in dplyr? - rDeployment mode in "SPARK-SUBMIT" - yarnBash: why does comparison priority matter with wildcards? - bashColdFusion ReReplace reformat phone number - stringSelecting local files using watir-webdriver - ruby | fooobar.comThe best way to return a member variable of a vector to an external class is c ++All Articles