I have some native C++ code that I want to use in C# and after doing some research I decided to create a C++/CLI wrapper for the native code. So far, so good. When running the program that contains the C++/CLI class, it works perfectly, but when I try to create the library that will provide me the chance of using the functionality of the native code in C#, I get the aforementioned errors (LNK2028 and LNK2019). Although I have tried several configurations for the linker and the compiler, I still cannot manage to get rid of these errors.
This is the code for the working wrapper:
//Wrapper_src.h
#include <cstdio>
#include "Project_Manager.h"
using namespace System;
public ref class WrapperParabola
{
private:
ProjectManager *mainPM; //ProjectManager is the main class from the native code
public:
WrapperParabola()
{
mainPM = new ProjectManager;
}
void InitSphereInfo(float R, float Cx, float Cy, float Cz, float H0, float H1, float dH, int segm)
{
mainPM->Init_SphereInfo(R, Cx, Cy, Cz, H0, H1, dH, segm);
}
void InitParableInfo(float P, float Refl, int Lsegm, int HSegm, float Lng)
{
mainPM->Init_ParableInfo(P, Refl, Lsegm, HSegm, Lng);
}
void InitRaysSetUpInfo(float Ora0, float Ora1, float dOra, int GridN, int NRays)
{
mainPM->Init_RaysSetUpInfo(Ora0, Ora1, dOra, GridN, NRays);
}
void InitSTPInfo(int zi, int luna, float LongLegala, float LongLoc, float Latitudine, float OraLegala, float UnghiInclinare, float UnghiAbatere)
{
mainPM->Init_STPInfo(zi, luna, LongLegala, LongLoc, Latitudine, OraLegala, UnghiInclinare, UnghiAbatere);
}
void ProcessData(void)
{
mainPM->ProcessData();
}
void PrintOutputData(void)
{
mainPM->PrintOutputData();
}
~WrapperParabola()
{
this->!WrapperParabola();
}
!WrapperParabola()
{
delete mainPM;
}
};
int main(void)
{
/*********************Test**********************/
WrapperParabola^ wrapperP = gcnew WrapperParabola;
//Init input data
wrapperP->InitSphereInfo(0, 0, 0, 0, 0, 0, 0, 0);
wrapperP->InitParableInfo(0, 0, 0, 0, 0);
wrapperP->InitRaysSetUpInfo(0, 0, 0, 0, 0);
wrapperP->InitSTPInfo(0, 0, 0, 0, 0, 0, 0, 0);
//Process read data
wrapperP->ProcessData();
//Print the results
wrapperP->PrintOutputData();
Console::WriteLine("Data Processed Successfully!");
std::getchar();
return 0;
}
And this is the code for the Library that I am trying to build:
// CppCodeManagerLib.h
#pragma once
#include "Project_Manager.h"
using namespace System;
namespace CppCodeManagerLib {
public ref class CodeManager
{
private:
ProjectManager *mainPM;
public:
CodeManager()
{
mainPM = new ProjectManager;
}
void InitSphereInfo(float R, float Cx, float Cy, float Cz, float H0, float H1, float dH, int segm)
{
mainPM->Init_SphereInfo(R, Cx, Cy, Cz, H0, H1, dH, segm);
}
/*...*/
};
}
As I said, I am interested in the changes that I have to make to the code (either to the native one or to the managed one) or to the commands and restrictions provided to the linker and to the compiler, in order to make the code usable in C#.
P.S: The complete errors are:
Error 2 error LNK2028:unresolved token (0A00003A) "public: void __thiscall ProjectManager::Init_SphereInfo(float,float,float,float,float,float,float,int)"
(?Init_SphereInfo@ProjectManager@@$$FQAEXMMMMMMMH@Z) referenced in function "public: void __clrcall CppCodeManagerLib::CodeManager::InitSphereInfo(float,float,float,float,float,float,float,int)"
(?InitSphereInfo@CodeManager@CppCodeManagerLib@@$$FQ$AAMXMMMMMMMH@Z) E:\Documents and Settings\zalman\Desktop\CppCodeManagerLib\CppCodeManagerLib\CppCodeManagerLib.obj CppCodeManagerLib
and
Error 3 error LNK2019: unresolved external symbol "public: void __thiscall ProjectManager::Init_SphereInfo(float,float,float,float,float,float,float,int)"
(?Init_SphereInfo@ProjectManager@@$$FQAEXMMMMMMMH@Z) referenced in function "public: void __clrcall CppCodeManagerLib::CodeManager::InitSphereInfo(float,float,float,float,float,float,float,int)"
(?InitSphereInfo@CodeManager@CppCodeManagerLib@@$$FQ$AAMXMMMMMMMH@Z) E:\Documents and Settings\zalman\Desktop\CppCodeManagerLib\CppCodeManagerLib\CppCodeManagerLib.obj CppCodeManagerLib
Thanks!