Hi, I want to call functions from C dll in C ++ / CLI. C functions are declared extern. I followed this dll binding guide: http://social.msdn.microsoft.com/Forums/en/Vsexpressvc/thread/84deabaa-ae82-47cc-aac0-592f5a8dfa22 and then in my C ++ / CLI dll I have following:
// 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); } }; }
I know that I should only give signatures in .h, and then write the function code in .cpp, but for testing I write it there. These are the errors I get:
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)
I tried to find them, but I can not find a lot of information about them, except that they are due to poor communication ...
UPDATE: Project Management ...
So, for my C ++ / cli project, I wrote .hpp as follows, which includes my 880+ headers:
extern "C" { #include "accrued.h" ... #include "gtobf.h"
following: gtobf.h:
#ifndef ALIB_GTOBF_H #define ALIB_GTOBF_H #include "cgeneral.h" #include "optprop.h" #include "cmemory.h" #include "rtnewton.h" #ifdef __cplusplus extern "C" { #endif
Then in my C ++ / cli shell, I turn on my all.hpp, which includes all the other headers ... In doing so, I still get errors.
I am sure that the function is exported because I used the dll from C # using P / Invoke ...
!!!!!!!!!!!!!!!! EDIT:
I have not indicated the correct path for lib ... Now I have parsed this and I get error LNK1104 saying that it cannot open my .lib