.net — c ++ lnk 2028, lnk 2020, lnk 2019 и lnk 2001 при импорте DLL

Несколько дней назад я задал похожий вопрос, который помог мне смотреть в правильном направлении с помощью __declspec (), но я снова застрял. Я буду как можно яснее. Надеюсь, кто-нибудь скажет мне, что я делаю не так. Это, вероятно, что-то маленькое и простое.

Информация о проектах:

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

файлы jc:

ПРИМЕЧАНИЕ. Я оставил resource.h, stdafx.h / cpp и AssemblyInfo.cpp без изменений.

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

file.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(){}

тестовые файлы:

test.cpp

#include "../jc/jc.h"int main(void)
{
int x = test_var;
test_func();
test_class obj;
return 0;
}

это ошибка, которую я получаю:

1>main.obj : error LNK2028: unresolved token (0A000009) "public: __thiscall test_class::test_class(void)" (??0test_class@@$$FQAE@XZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>main.obj : error LNK2028: unresolved token (0A00000A) "void __cdecl test_func(void)" (?test_func@@$$FYAXXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>main.obj : error LNK2020: unresolved token (0A00000B) "__declspec(dllimport) int test_var" (__imp_?test_var@@3HA)
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall test_class::test_class(void)" (??0test_class@@$$FQAE@XZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl test_func(void)" (?test_func@@$$FYAXXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int test_var" (__imp_?test_var@@3HA)

Я застрял с этой проблемой в течение нескольких дней, я надеюсь, что кто-то может мне помочь.

Спасибо!

1

Решение

Нашел ответ. Ошибка не была в коде. Я не знал, что мне нужно было включить файл «.lib» в «дополнительные зависимости» в параметрах «компоновщик / ввод» свойств «dll». Это видео прояснило: «http://www.youtube.com/watch?v=yEqRyQhhto8».

1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector