Home > Software engineering > VS2015 different simulate DLL global variable transmission error, the DLL function is no problem?
VS2015 different simulate DLL global variable transmission error, the DLL function is no problem?
Time:09-24
A module is C A.H
extern int _declspec (dllexport) test_dllGlobalVar1;
A.C
test_dllGlobalVar1=100;
Hope module B calls test_dllGlobalVar1
Module B is a WIN32 console application, including
1, stdafx. H
# pragma once # include "targetver. H" # include & lt; stdio.h> # include & lt; Tchar. H> Extern "C" { # include "test_dllGlobalvar. H" }
2, the biggest pp
# pragma comment (lib, a. "ib") Extern int _declspec (dllimport) test_dllGlobalVar1; Int main () { Test_dllGlobalVar1=100; }
A module a. ib and a. d. ll is already good, and the other functions can be B right call, is there A problem is A global variable, compilation of B prompt DLL links, then connect the run into the error, the following error message
Severity code shows line project file Error LNK2001 cannot resolve the external symbol of _test_dllGlobalVar1 B D: \ Test_Program \ B.o bj 1 Severity code shows line project file Warning C4273 "test_dllGlobalVar1" : DLL links inconsistent B d: \ test_program \ biggest pp 25 Severity code shows line project file 1 error LNK1120 cannot resolve the external command B D: \ Test_Program \ Debug \ B.e xe 1
Why is that? Yesterday, I all right call over a period of time (DLL global variables and DLL function calls), then don't know which changed the environment Settings, has been around the error, function DLL call has been no problem, is a global variable has a problem, please directly,
CodePudding user response:
extern int _declspec (dllexport) test_dllGlobalVar1 () { The return of 100; }