我有一個簡單的功能是這樣的:使用模板功能的DLL中的另一個項目
cusp.dll
#define EXPORT extern "C" __declspec (dllexport)
EXPORT
void cuspDsolver(int *r, int *c, double *v, double *x, double *b, int size, int nnz,double tol)
{
.
.
.
.
.
}
,我創建了使用這兩種線DLL:
#define EXPORT extern "C" __declspec (dllexport)
EXPORT
,我用這個方法調用其他項目這個功能:
HINSTANCE hDLL = LoadLibrary("C:\\Users\\Administrator\\Documents\\Visual Studio 2012\\Projects\\Ardalan_12\\cusp.dll");
if(hDLL == NULL)
{
cout<< "Failed to load DLL" <<endl;
}
typedef void(*fnPtr)(int *, int *, double *, double *, double *, int , int ,double);
fnPtr pfn;
pfn=(fnPtr)GetProcAddress(hDLL,"cuspDsolver");
if(pfn)
{
pfn(rowOffset,colIndex,values,answer,rightHandSide,theSize,nnz,0.9);
}
FreeLibrary(hDLL);
這工作很細,但現在我改變了我的功能,這
//#define EXPORT extern "C" __declspec (dllexport)
//EXPORT
template <typename LinearOperator,typename Vector>
void cuspDsolver(LinearOperator& A,Vector& X,Vector& B,double tol)
{
cusp::default_monitor<double> monitor(B, 10000, tol);
cusp::precond::scaled_bridson_ainv<double,cusp::device_memory> PRE(A);
DWORD dw1 = GetTickCount();
cusp::krylov::cg(A,X,B,monitor,PRE);
DWORD dw2 = GetTickCount();
double dw3 = dw2 - dw1;
cout <<endl << "time spent is : " << dw3 << endl;
cout << endl << "developed by cusp!!!" << endl;
}
但Visual Studio將不允許的extern 「C」 __declspec(dllexport)的與模板函數有什麼辦法輕鬆做到這一點?其實我不是專家,所以你能詳細解釋一下嗎?
非常感謝你的回答,但是我的函數使用** CUSP **庫,它必須用** nvcc **編譯,但是我的其他項目是** VC++ **我想我不能包含它,你能解釋一下嗎?第二種方式多一點,或者引用我的鏈接,幫助我理解你的目的是什麼? – Alexander1991
@ user3297741我真的不明白爲什麼你無法將CUSP鏈接到VS項目中。畢竟,CUDA SDK包含用於CUDA文件的VS集成。究竟是什麼問題? – Angew
其實我也不知道,但這裏[在Visual Studio C++項目中使用CUSP](http://stackoverflow.com/questions/21942540/using-cusp-in-a-visual-studio-c-project)說所以。 – Alexander1991