Include external libraries in Mex files

5 vues (au cours des 30 derniers jours)
Muser10101010
Muser10101010 le 2 Juil 2015
Commenté : Muser10101010 le 2 Juil 2015
I am just playing around with mex files and wish to call an external library in a mex file. I have this code and some more after it. The linking fails even though I include everything in the -I -L and -i options.
#include "gdcmImageReader.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
char *filename;
filename = mxArrayToString(prhs[0]);
gdcm::ImageReader reader;
reader.SetFileName( filename );
then when I compile I get something like this
error LNK2019: unresolved external symbol "public: void __cdecl gdcm::Reader::SetFileName(char const *)" (?SetFileName@Reader@gdcm@@QEAAXPEBD@Z) referenced in function mexFunction
Are you allowed to call external libraries?
  2 commentaires
James Tursa
James Tursa le 2 Juil 2015
You need to show us the exact commands you are using to mex the code. What you are currently doing is not linking in the necessary libraries.
Muser10101010
Muser10101010 le 2 Juil 2015
Hi, this is the code so far
#include "gdcmImageReader.h"
#include <iostream>
#include <stdio.h>
#include "mex.h"
using namespace gdcm;
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
char *filename;
FILE * pFile;
if( nrhs != 1 || !mxIsChar(prhs[0]) ) {
mexErrMsgTxt("Need filename character string input.");
}
filename = mxArrayToString(prhs[0]);
pFile= fopen(filename, "rb");
mxFree(filename);
if( pFile == NULL ) {
mexErrMsgTxt("File did not open.");
}
gdcm::ImageReader reader;
reader.SetFileName( filename );
if( !reader.Read() ) {
char str[80];
strcpy(str, "could not read the dicom file: ");
strcat(str, filename);
mexErrMsgTxt(str);
}
}
I then compile with this (I have the .lib files in pwd/lib and include files in pwf/include)
mex -v -I.\include -L.\lib -lgdcmCommon -lgdcmDICT -lgdcmDSED -lgdcmIOD -lgdcmMEXD -lgdcmMSFF -lgdcmcharls -lgdcmexpat -lgdcmgetopt -lgdcmjpeg12 -lgdcmjpeg16 -lgdcmjpeg8 -lgdcmopenjpeg -lgdcmzlib -lsocketxx testreader.cpp

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by