几天前,我问了一个类似的问题,它帮助我用__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: jcjc文件:
注意:我没有修改Resoure.h、stdafx.h/cpp和AssemblyInfo.cpp。
jc.h
#ifndef JC_H
#define JC_H
#include "def.h"
#include "file.h"
#endifdef.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
#endiffile.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?
};
#endiffile.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)我已经被这个问题困了几天了,我希望有人能帮我。
谢谢!
发布于 2013-01-13 20:47:03
找到答案了。错误不在密码里。我不知道必须在"dll“属性的”链接器/输入“选项中将".lib”文件包含到“附加依赖项”中。这段视频清楚地表明:"http://www.youtube.com/watch?v=yEqRyQhhto8.“
https://stackoverflow.com/questions/14280582
复制相似问题