1

数日前、私は __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

ファイル.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)

私はこの問題で数日間立ち往生しています。誰かが私を助けてくれることを願っています。

ありがとうございました!

4

1 に答える 1

1

答えを見つけました。間違いはコードにありませんでした。「dll」プロパティの「リンカー/入力」オプションで「追加の依存関係」に「.lib」ファイルを含める必要があることを知りませんでした。このビデオは、「http://www.youtube.com/watch?v=yEqRyQhhto8」を明らかにしました。

于 2013-01-13T20:47:03.657 に答える