2012-02-21 6 views
1

私はC#でネイティブなC++コードを使用したいのですが、いくつかの研究をした後にネイティブコード用のC++/CLIラッパーを作成することにしました。ここまでは順調ですね。 C++/CLIクラスを含むプログラムを実行すると完全に動作しますが、C#でネイティブコードの機能を使用するライブラリを作成しようとすると、前述のエラーが発生します(LNK2028およびLNK2019 )。私はリンカとコンパイラのいくつかの設定を試みましたが、私はまだこれらのエラーを取り除くことはできません。C++/CLIからアンマネージC++を呼び出そうとするとエラーが発生する

これは、作業ラッパーのコードです:

//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; 
} 

そして、これは私が構築しようとしていますライブラリのコードです:私は、私は、言ったように

// 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); 
    } 

    /*...*/ 
}; 
} 

C#でコードを使用できるようにするために、コード(ネイティブコードまたは管理されているコード)またはリンカとコンパイラに与えられたコマンドと制限に加えなければならない変更に興味があります。

P.S:完全なエラーは以下のとおりです。

Error 2 error LNK2028:unresolved token (0A00003A) "public: void __thiscall ProjectManager::Init_SphereInfo(float,float,float,float,float,float,float,int)" 
([email protected]@@[email protected]) referenced in function "public: void __clrcall CppCodeManagerLib::CodeManager::InitSphereInfo(float,float,float,float,float,float,float,int)" 
([email protected]@[email protected]@[email protected]) E:\Documents and Settings\zalman\Desktop\CppCodeManagerLib\CppCodeManagerLib\CppCodeManagerLib.obj CppCodeManagerLib 

Error 3 error LNK2019: unresolved external symbol "public: void __thiscall ProjectManager::Init_SphereInfo(float,float,float,float,float,float,float,int)" 
([email protected]@@[email protected]) referenced in function "public: void __clrcall CppCodeManagerLib::CodeManager::InitSphereInfo(float,float,float,float,float,float,float,int)" 
([email protected]@[email protected]@[email protected]) E:\Documents and Settings\zalman\Desktop\CppCodeManagerLib\CppCodeManagerLib\CppCodeManagerLib.obj CppCodeManagerLib 

ありがとう!

+1

エラー番号だけでなく、実際のエラーメッセージを投稿してください。また、 '/ clr'や'/clr:pure'を使っていますか? – ildjarn

+0

@ildjarn。私はcompelteエラーメッセージを出しました。また、 '/ clr'を使っています。 – ZLMN

+0

ProjectManagerの実装を含むライブラリをリンカの入力に追加したとしますか? – jarmond

答えて

関連する問題