Il ya quelques jours, j'ai posé une question similaire, ce qui m'a aidé à regarder dans la bonne direction avec __declspec(), mais je suis resté coincé. Je serai aussi clair que possible. J'espère que quelqu'un pourra me dire ce que je fais de mal. C'est probablement quelque chose de petit et simple.C++ lnk 2028, lnk 2020, lnk 2019 et lnk 2001 lors de l'importation dll
Informations Projets:
jc:
project type: Class Library
configuration type: Dynamic Library (.dll)
common runtime language support: /clr
references: System
System.Data
System.Drawing
System.Windows.Forms
System.Xml
test (start up project):
project type: CLR Empty project
configuration type: Application (.exe)
common runtime language support: /clr
references: jc
project dependencies: jc
fichiers jc:
NOTE: Je suis parti resource.h, stdafx.h/cpp et AssemblyInfo.cpp inchangé.
jc.h
#ifndef JC_H
#define JC_H
#include "def.h"
#include "file.h"
#endif
def.h
#ifndef JC_DEF_H
#define JC_DEF_H
#ifdef JC_API_DEFINITIONS
# define JC_API __declspec(dllexport)
#else
# define JC_API __declspec(dllimport)
#endif
#endif
fichier.h
#ifndef JC_FILE_H
#define JC_FILE_H
#include "def.h"
extern JC_API int test_var;
JC_API void test_func(void);
class JC_API test_class
{
public:
__thiscall test_class();//I inserted __thiscall for compatibility with other compilers. Is this necessary and should I use it for the definition as well?
};
#endif
file.cpp
#include "StdAfx.h"
#define JC_API_DEFINITIONS
#include "file.h"
JC_API int test_var = 10;
JC_API void test_func(void){}
__thiscall test_class::test_class(){}
fichiers de test:
TEST.CPP
#include "../jc/jc.h"
int main(void)
{
int x = test_var;
test_func();
test_class obj;
return 0;
}
ce sont l'erreur que je reçois:
1>main.obj : error LNK2028: unresolved token (0A000009) "public: __thiscall test_class::test_class(void)" ([email protected]@[email protected]) referenced in function "int __cdecl main(void)" ([email protected]@$$HYAHXZ)
1>main.obj : error LNK2028: unresolved token (0A00000A) "void __cdecl test_func(void)" ([email protected]@$$FYAXXZ) referenced in function "int __cdecl main(void)" ([email protected]@$$HYAHXZ)
1>main.obj : error LNK2020: unresolved token (0A00000B) "__declspec(dllimport) int test_var" ([email protected]@3HA)
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall test_class::test_class(void)" ([email protected]@[email protected]) referenced in function "int __cdecl main(void)" ([email protected]@$$HYAHXZ)
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl test_func(void)" ([email protected]@$$FYAXXZ) referenced in function "int __cdecl main(void)" ([email protected]@$$HYAHXZ)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int test_var" ([email protected]@3HA)
Je suis coincé avec ce problème pendant quelques jours, je J'espère que quelqu'un peut m'aider.
Merci!