loadlibrary and 64bit shared lib (DLL) on 64bit windows 7
古いコメントを表示
Hi All,
I have source of a library which compiles and loads fine on 64bit unix and 32 bit windows. Now I am trying to compile the dll on win7 64 bit with vs studio 8 (32 bit with win64 option) but I keep getting and error when using loadlibrary in matlab (2011b) for the dll which I have managed to compile.
The error is simply:
Error using loadlibrary (line 421)
Building libTestDLL_thunk_pcwin64 failed.
After this error, I get a bunch of errors on my h file like:
error C2134 syntax error : missing ')' before '*'
So my h file is wrong ?
I am not sure what is going on here. I have read that the 64bit matlab loadlibrary expects special treatment of file extension c vs c++ ? What is the right way to compile my libary so that it doesn't give problems with loadlibrary ?
This is my main h file for the library:
#ifndef TestDLL_h
#define TestDLL_h
/* This is from shrhelp.h */
#ifndef SHRHELP
#define SHRHELP
#ifdef _WIN32
#ifdef EXPORT_FCNS
#define EXPORTED_FUNCTION __declspec(dllexport)
#else
#define EXPORTED_FUNCTION __declspec(dllimport)
#endif
#else
#define EXPORTED_FUNCTION
#endif
#endif
/* end shrhelp.h section */
#ifdef __cplusplus
extern "C"
{
#endif
EXPORTED_FUNCTION void testLoadData( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] );
#ifdef __cplusplus
}
#endif
#endif /* TestDLL_h */
This is one of my cpp files:
#include "mex.h"
#include "matrix.h"
#define EXPORT_FCNS
#include "TestDLL.h"
#include "StaticControl.h"
#include "volume.h"
#include <stdio.h>
#include <stdlib.h>
StaticControl g_Control;
#ifdef __cplusplus
extern "C" {
#endif
EXPORTED_FUNCTION void testLoadData( int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[] )
{
if (nlhs > 0)
mexErrMsgTxt("Too many output arguments.");
if (nrhs != 5)
mexErrMsgTxt("Format: ID, xVals, yVals, zVals, volumeData");
if (!mxIsChar(prhs[0]))
mexErrMsgTxt("ID should be a string.");
if (!mxIsDouble(prhs[1]))
mexErrMsgTxt("xVals should be an array of doubles.");
if (!mxIsDouble(prhs[2]))
mexErrMsgTxt("yVals should be an array of doubles.");
if (!mxIsDouble(prhs[3]))
mexErrMsgTxt("zVals should be an array of doubles.");
if (!mxIsDouble(prhs[4]))
mexErrMsgTxt("volumeData should be an array of doubles.");
return;
}
#ifdef __cplusplus
}
#endif
If there is a recommended way of doing this I will be glad to hear
Thank you
GT
2 件のコメント
Walter Roberson
2012 年 4 月 9 日
Greg, in the list of errors, is there perhaps one that says something about not being able to open a file that ends with .h such as windows.h ?
Greg Thom
2012 年 4 月 10 日
採用された回答
その他の回答 (1 件)
Philip Borghesani
2012 年 4 月 10 日
When building the thunk file your header file must be able to compile standalone. Your header file needs mex.h as a prerequisite so it should have the line #include <mex.h> near the beginning of the file.
The key compile error is the second one: The compiler does not know what an mxArray is.
The standard header parser in loadlibrary requires standalone headers too but it is a bit more forgiving about missing definitions of standard data types.
The best way to test a header file is to create and compile the the file main.c with:
#include "myHeader.h"
int main(int, char **)
{
}
Creating header files that meet this requirement is a common best practice in modern c and c++ programming.
カテゴリ
ヘルプ センター および File Exchange で C Shared Library Integration についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!