C shared library call error
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all,
I create a C shared library from a .m file and get .dll/.h/.lib files successfully. But when I try to call the library in Visual Studio 2008 I meet these problems:
“error LNK2001: unresolved external symbol mclGetMatrix_730_proxy”
“error LNK2001: unresolved external symbol array_ref_get_numeric_mxDouble_730_proxy”
Do you have any idea about this problem?
My MATLAB version: R2012a
MATLAB compiler: v717
Operating system: 64-bit windows 7
The main h file for the library:
#ifndef __libImageClean_h
#define __libImageClean_h 1
#if defined(__cplusplus) && !defined(mclmcrrt_h) && defined(__linux__)
# pragma implementation "mclmcrrt.h"
#endif
#include "mclmcrrt.h"
#include "mclcppclass.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__SUNPRO_CC)
/* Solaris shared libraries use __global, rather than mapfiles
* to define the API exported from a shared library. __global is
* only necessary when building the library -- files including
* this header file to use the library do not need the __global
* declaration; hence the EXPORTING_<library> logic.
*/
#ifdef EXPORTING_libImageClean
#define PUBLIC_libImageClean_C_API __global
#else
#define PUBLIC_libImageClean_C_API /* No import statement needed. */
#endif
#define LIB_libImageClean_C_API PUBLIC_libImageClean_C_API
#elif defined(_HPUX_SOURCE)
#ifdef EXPORTING_libImageClean
#define PUBLIC_libImageClean_C_API __declspec(dllexport)
#else
#define PUBLIC_libImageClean_C_API __declspec(dllimport)
#endif
#define LIB_libImageClean_C_API PUBLIC_libImageClean_C_API
#else
#define LIB_libImageClean_C_API
#endif
/* This symbol is defined in shared libraries. Define it here
* (to nothing) in case this isn't a shared library.
*/
#ifndef LIB_libImageClean_C_API
#define LIB_libImageClean_C_API /* No special import/export declaration */
#endif
extern LIB_libImageClean_C_API
bool MW_CALL_CONV libImageCleanInitializeWithHandlers(
mclOutputHandlerFcn error_handler,
mclOutputHandlerFcn print_handler);
extern LIB_libImageClean_C_API
bool MW_CALL_CONV libImageCleanInitialize(void);
extern LIB_libImageClean_C_API
void MW_CALL_CONV libImageCleanTerminate(void);
extern LIB_libImageClean_C_API
void MW_CALL_CONV libImageCleanPrintStackTrace(void);
extern LIB_libImageClean_C_API
bool MW_CALL_CONV mlxImageClean(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
/* On Windows, use __declspec to control the exported API */
#if defined(_MSC_VER) || defined(__BORLANDC__)
#ifdef EXPORTING_libImageClean
#define PUBLIC_libImageClean_CPP_API __declspec(dllexport)
#else
#define PUBLIC_libImageClean_CPP_API __declspec(dllimport)
#endif
#define LIB_libImageClean_CPP_API PUBLIC_libImageClean_CPP_API
#else
#if !defined(LIB_libImageClean_CPP_API)
#if defined(LIB_libImageClean_C_API)
#define LIB_libImageClean_CPP_API LIB_libImageClean_C_API
#else
#define LIB_libImageClean_CPP_API /* empty! */
#endif
#endif
#endif
extern LIB_libImageClean_CPP_API void MW_CALL_CONV ImageClean(int nargout, mwArray& E, const mwArray& Img, const mwArray& radian);
#endif
#endif
one of the cpp file:
#include "stdafx.h"
#include "libImageClean.h"
#include "mclmcrrt.h"
//#include "mclmcr.h"
#include "mclcppclass.h"
#include "matrix.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <string.h>
#include <windows.h>
#define _abs(x) ((x) > 0?(x):-(x))
int _tmain(int argc, _TCHAR* argv[])
{
char image_name[1024] = "C:\\Qualcomm\\100CASIO\\contact fps\\";
char file_name1[1024];
char file_name2[1024];
int Num_F = 500;
int channel;
int i,j;
IplImage* Img1 = NULL;
IplImage* Img2 = NULL;
int height,width;
uchar threshold = 120;
double* radian = new double[1]();
radian[0] = 7;
double* fps = new double[1]();
double *sd = new double[Num_F]();
for(int ii=1;ii<Num_F-1;i++)
{
sprintf(file_name1, "%s%d%s", image_name, ii, ".jpg");
sprintf(file_name2, "%s%d%s", image_name, ii+1, ".jpg");
if((Img1 = cvLoadImage(file_name1,1))==0) //
{
printf("Can not read image1!");
return -1;
}
if((Img2 = cvLoadImage(file_name2,1))==0) //
{
printf("Can not read image2!");
return -1;
}
height = Img1->height;
width = Img1->width;
uchar *imagedata1 = (uchar*)Img1->imageData;
uchar *imagedata2 = (uchar*)Img2->imageData;
ImageThresh(imagedata1,threshold,width,height);
ImageThresh(imagedata2,threshold,width,height);
double *diffimage = new double[width*height]();
for(j=0;j<height;j++)
{
for(i=0;i<width;i++)
{
diffimage[j*width+i] = _abs(imagedata1[j*width+i]-imagedata2[j*width+i]);
}
}
// initialize
if(!mclInitializeApplication(NULL,0) )
{
printf("Could not initialize the application!");
return -1;
}
if(!libImageCleanInitialize())
{
printf("Could not initialize libtestdiff!");
return -1;
}
mwArray a(width,height,mxDOUBLE_CLASS);
mwArray b(1,1,mxDOUBLE_CLASS);
mwArray c(width,height,mxDOUBLE_CLASS);
a.SetData(diffimage,width*height);
b.SetData(radian,1);
// call the function
ImageClean(1,c,a,b);
c.GetData(diffimage,width*height);
// terminate the lib
libImageCleanTerminate();
// terminate MCR
mclTerminateApplication();
sd[ii] = GetImageSum(diffimage,width,height);
delete[] diffimage;
delete[] radian;
}
return 0;
}
Thanks.
0 Kommentare
Antworten (3)
Kaustubha Govind
am 5 Sep. 2012
Is your Visual Studio configured to compile a 32-bit executable perhaps? This won't work because the compiled shared library is a 64-bit binary, so you need to configure Visual Studio for a 64-bit target.
0 Kommentare
Siehe auch
Kategorien
Mehr zu C Shared Library Integration finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!