フィルターのクリア

Include external libraries in Mex files

5 ビュー (過去 30 日間)
Muser10101010
Muser10101010 2015 年 7 月 2 日
コメント済み: Muser10101010 2015 年 7 月 2 日
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 件のコメント
James Tursa
James Tursa 2015 年 7 月 2 日
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 2015 年 7 月 2 日
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

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by