VS2015 - 与C DLL的链接CRL

VS2015 — Link CRL with C++ DLL

本文关键字:链接 CRL DLL VS2015      更新时间:2023-10-16

我是C#程序员,我正在尝试制作C /CLI包装器。解决方案中有三个项目:

  • C DLL
  • C CLR
  • WPF C#

我只是在进行测试,所以我得到了这些实现:

c dll testing.h:

class Test
{
public:
    Test();
    ~Test();
    int Increment();
private:
    int counter = 5;
};`

c dll testing.cpp

#include "Testing.h"
int Test::Increment()
{
    return counter++;
}

clr wrapper.h

#pragma once
#include "Testing.h"
using namespace System;
namespace Wrapper
{
    public ref class Wraptest
    {
    public:
        Wraptest();
        int Increment();
    private:
        Test* t;
    };
}

clr wrapper.cpp

#include "stdafx.h"
#include "Wrapper.h"
#include "PITest.h"
Wrapper::Wraptest::Wraptest()
{
    t = new Test();
}
int Wrapper::Wraptest::Increment()
{
    return t->Increment();
}

我已经在包装器项目中添加了对测试C DLL项目的参考。我还将DLL解决方案标头文件添加到包装器的附加内容中。

C DLL项目构建良好,但是当我构建包装器项目时,我会得到以下错误:

严重性代码描述项目文件行抑制状态 错误lnk2028未解决的令牌(0A000007("公共:__thiscall test :: test(void("(函数中引用的___clrcall wrapper :: wraptest :: wraptest :: wraptest :: wraptest(void((void((void((void("(?? 0wraptest@wrapper @@ $$ fq $ aam@xz(包装c: users mytoy documents documents visual Studio 2015 projects codetest codetest wrapper wrapper wrapper.obj 1

严重性代码描述项目文件行抑制状态 错误lnk2019未解决的外部符号" public:__thiscall test :: test(void("(函数中引用的" test(void("(?? 0test @@ $$ fqae@xz(公共:__clrcall wrapper :: wraptest :: wraptest :: wraptest :: wraptest :: wraptest(void(0wraptest@wrapper @@ $$ fq $ aam@xz(包装c: users mytoy documents documents visual Studio 2015 projects codetest codetest wrapper wrapper wrapper.obj 1

严重性代码描述项目文件行抑制状态 错误lnk1120 2未解决的外部包装器C: users mytoy documents visual Studio 2015 project codetest debug debug wrapper.dll 1


我无法找出解决方案。谢谢。

好吧,我设法使它起作用。这很容易。

我检查了此链接,但我缺少以下内容:

// C++ DLL Header
#ifdef TESTING_EXPORTS  
    #define TESTING_API __declspec(dllexport)   
#else  
    #define TESTING_API __declspec(dllimport)   
#endif

在包装器上,我刚刚将标题位置添加到附加的目录(链接器不变(,我只是开箱即用。