本文介绍了C ++ LNK 2028,LNK 2020年,LNK 2019和2001年LNK导入时DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个小时前我问过类似的问题,这让我看在正确的方向__declspec(),但我得到了一次卡。我会尽可能明确。希望有人能告诉我什么,我做错了。这可能是一些小而简单。

A few day ago I asked a similar question, which helped me look in the right direction with __declspec(), but I got stuck again. I'll be as clear as possible. Hopefully someone can tell me what I'm doing wrong. It is probably something small and simple.

项目信息:

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不变

NOTE: I left resource.h, stdafx.h/cpp and AssemblyInfo.cpp unchanged.

jc.h

#ifndef JC_H
#define JC_H
#include "def.h"
#include "file.h"
#endif

def.h

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

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

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)

我一直坚持这个问题几天,我希望有人能帮助我。

I've been stuck with this problem for a few days, I hope someone can help me.

感谢您!

推荐答案

找到了答案。这个错误是不是在code。我不知道我必须包括名为.lib文件中的DLL属性链接器/输入选项为额外的依赖。该视频清楚:http://www.youtube.com/watch?v=yEqRyQhhto8

Found the answer. The mistake wasn't in the code. I didn't know I had to include the ".lib" file to "additional dependencies" in "linker/input" options of the "dll" properties. This video made it clear: "http://www.youtube.com/watch?v=yEqRyQhhto8."

这篇关于C ++ LNK 2028,LNK 2020年,LNK 2019和2001年LNK导入时DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-07 21:41