C ++/CLI Visual Studio 2010からVS 2005でコンパイルされたネイティブCを呼び出す - .libファイルを開くことはできません…
-
30-10-2019 - |
質問
こんにちは私はc dllからc ++/cliへの関数を呼び出したいです。 C関数は外部と宣言されます。 DLLをリンクするために、このチュートリアルに従いました。 http://social.msdn.microsoft.com/forums/en/vsexpressvc/thread/84deabaa-ae82-47cc-aac0-592f5a8dfa22 そして、私のc ++/cli dllには、次のことがあります。
// testWrapper.h
#pragma once
using namespace System;
namespace testWrapper {
extern "C" int GtoCalcImpliedVolatility2(
double premium,
int optionType,
double underPrice,
double strike,
double yearsToExpiry,
double yearsToPayment,
double volGuess,
double discountRate,
double dividendRate,
double growthRate,
double *impliedVol);
public ref class MyNamesSplitterClass
{
private:
public:
int TestSomething()
{
double vol;
int _status = GtoCalcImpliedVolatility2(
0.098328, //premium
'P', //optionType
0.950000, //underPrice
1.050000, //strike
0.900000, //yearsToExpiry
0.95, //yearsToPayment
0.01, //volGuess
0.02, //discountRate
0.03, //dividendRate
0.04,//growthRate
&vol);
}
};
}
.hで署名のみを提供し、.cppで関数コードを書き込むことになっていることを知っていますが、テストのために同じ場所で書いています。これらは私が得るエラーです:
Error 3 error LNK1120: 2 unresolved externals (etc...)
Error 1 error LNK2028: unresolved token (0A000006) "int __cdecl testWrapper::GtoCalcImpliedVolatility2(double,int,double,double,double,double,double,double,double,double,double *)" (?GtoCalcImpliedVolatility2@testWrapper@@$$FYAHNHNNNNNNNNPAN@Z) referenced in function "public: int __clrcall testWrapper::MyNamesSplitterClass::TestSomething(void)" (?TestSomething@MyNamesSplitterClass@testWrapper@@$$FQ$AAMHXZ)
Error 2 error LNK2019: unresolved external symbol "int __cdecl testWrapper::GtoCalcImpliedVolatility2(double,int,double,double,double,double,double,double,double,double,double *)" (?GtoCalcImpliedVolatility2@testWrapper@@$$FYAHNHNNNNNNNNPAN@Z) referenced in function "public: int __clrcall testWrapper::MyNamesSplitterClass::TestSomething(void)" (?TestSomething@MyNamesSplitterClass@testWrapper@@$$FQ$AAMHXZ)
私はそれらを調べようとしましたが、それらが悪いリンクによるものであるという事実を除いて、それらに関する多くの情報を見つけることができません...
更新:プロジェクトの組織...
したがって、C ++/CLIプロジェクトでは、880+ヘッダーを含む.HPPを次のように書きました。
extern "C" {
#include "accrued.h"
...
#include "gtobf.h" // this contains GtoCalcImpliedVolatility2
...
#include "../includep/zcsmthp.h"
}
以下はgtobf.hです。
#ifndef ALIB_GTOBF_H
#define ALIB_GTOBF_H
#include "cgeneral.h"
#include "optprop.h" /* TOptionProperties */
#include "cmemory.h" /* FREE macro */
#include "rtnewton.h" /* TObjectFunc */
#ifdef __cplusplus
extern "C"
{
#endif
/*f
* Calculates volatility implied by the price of a given option.
*/
//#define GTO_EXPORT(type) __declspec(dllexport) type
GTO_EXPORT(int ) GtoCalcImpliedVolatility2(
double premium, /* (I) Option premium */
int optionType, /* (I) GtoOPTION_PUT/GtoOPTION_CALL */
double underPrice, /* (I) Underlyer price */
double strike, /* (I) Strike/exercise price */
double yearsToExpiry, /* (I) Years to option's expiry */
double yearsToPayment, /* (I) Years till option pays off */
double volGuess, /* (I) Volatility guess (.06 for 6%) */
double discountRate, /* (I) Discount rate (ann. compound) */
double dividendRate, /* (I) Dividend rate (ann. compound) */
double growthRate, /* (I) Growth rate (ann. compound) */
double *impliedVol); /* (O) Implied Volatility */
//...other functions
#ifdef __cplusplus
}
#endif
#endif /* ALIB_GTOBF_H */
次に、C ++/CLIラッパーに、他のすべてのヘッダーを含むすべてのヘップを含めます...このすべてで、私はまだエラーを取得しています。
P/Invokeを使用してC#からDLLを使用したため、関数がエクスポートされると確信しています...
!!!!!!!!!!!!!!!編集:
私はlibの正しいパスを示していませんでした...今、私はそれを整理しました、そして、私はそれが私の.libを開けないというLNK1104エラーを取得しています
正しい解決策はありません
所属していません StackOverflow