首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >c++ lnk 2028,lnk 2020,lnk 2019和lnk 2001导入dll

c++ lnk 2028,lnk 2020,lnk 2019和lnk 2001导入dll
EN

Stack Overflow用户
提问于 2013-01-11 14:50:48
回答 1查看 1.2K关注 0票数 1

几天前,我问了一个类似的问题,它帮助我用__declspec()向正确的方向看,但是我又被困住了。我会尽可能清楚的。希望有人能告诉我我做错了什么。它可能是一个很小很简单的东西。

项目信息:

代码语言:javascript
复制
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文件:

注意:我没有修改Resoure.h、stdafx.h/cpp和AssemblyInfo.cpp。

jc.h

代码语言:javascript
复制
#ifndef JC_H
#define JC_H
#include "def.h"
#include "file.h"
#endif

def.h

代码语言:javascript
复制
#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

代码语言:javascript
复制
#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

代码语言:javascript
复制
#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

代码语言:javascript
复制
#include "../jc/jc.h"
int main(void)
{
    int x = test_var;
    test_func();
    test_class obj;
    return 0;
}

,这是我得到的错误:

代码语言:javascript
复制
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)

我已经被这个问题困了几天了,我希望有人能帮我。

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-13 20:47:03

找到答案了。错误不在密码里。我不知道必须在"dll“属性的”链接器/输入“选项中将".lib”文件包含到“附加依赖项”中。这段视频清楚地表明:"http://www.youtube.com/watch?v=yEqRyQhhto8.

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14280582

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档