Include external libraries in Mex files

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 Comments

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.
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

Sign in to comment.

Answers (0)

Categories

Products

Asked:

on 2 Jul 2015

Commented:

on 2 Jul 2015

Community Treasure Hunt

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

Start Hunting!