我在一个问题上看不到链接静态C++/CLI库的问题,所以我生成了一个动态链接并尝试在C++ CLR控制台中链接它项目没有成功 我得到: 错误1错误LNK2020:无法解析的令牌(06000001)cBox ::。ctor pTest9.obj
我把dll(项目 - >参考 - >添加新的参考)设置包含文件在项目 (包括没有代码文件)在一个CLR控制台项目中链接一个C++/CLI库
我不知道该怎么办(我是用C++/CLI新)
感谢建议/解决方案
图书馆项目申报为DLL
#include "stdafx.h"
using namespace System;
ref class cBox
{
public:
cBox() ;
cBox(double lv,double bv,double hv);
double Volume();
private:
double Length;
double Width;
double Height;
};
代码库的:
#include "stdafx.h"
#include "cBox.h"
cBox::cBox()
{
Console::WriteLine(L"No arg constructor called");
Length = 1.0 ;
Width = 1.0 ;
Height = 1.0 ;
}
cBox::cBox(double lv,double bv,double hv)
{
Console::WriteLine(L"Constructor called");
Length = lv;
Width = bv;
Height = hv;
}
double cBox::Volume()
{
return Length*Width*Height;
}
然后在控制台CLR项目我尝试这个链接库,我得到它的.h文件中
#include "stdafx.h"
#include "cBox.h"
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Test Library:\n");
cBox^ oBox; // handle of type box
oBox = gcnew cBox;
Console::WriteLine(L"Default Box Volume {0}",oBox->Volume());
return 0;
}
如果我们能够帮助您,我们需要查看代码 – Dervall 2012-02-25 11:38:21
因此,您希望使用C++将某些代码编译为托管程序集。然后你想使用该程序集中的.lib文件? – 2012-02-25 11:39:18
其实应该有可能。请你提供一些关于你的代码和项目布局的更多信息和例子。 – MajesticRa 2012-02-25 11:40:03