PDA

View Full Version : QT 5 Matlab Compiler Runtime Static Library Linking Problem



subhagato
29th July 2013, 15:00
Hi All,

I have migrated from QT 4.7 to QT 5.1. I have a code for compiling a .dll file for a plugin in my software. The .pro file is here.



DccSrc = ../../
include($$DccSrc"DccGlobals.pri")

TEMPLATE = lib
CommonPath = $$DccSrc"Common"
DEPENDPATH += . Interface $$CommonPath
DLLDESTDIR = $$DCC_BIN/plugins

DEFINES += MTF_LIBRARY
DEFINES += QT __LCC__

SOURCES += MTF.cpp \
LibTI_MTF.c \
LibTI_MTF_mcc_component_data.c

HEADERS += MTF.h \
LibTI_MTF.h \
../../../Common/ctypes.h

INCLUDEPATH += . $$CommonPath ../../MatLabHFilesForQT "C:\Program Files\MATLAB\MATLAB Compiler Runtime\v713\extern\include"


LIBS += -L"C:/Program Files/MATLAB/MATLAB Compiler Runtime/v713/extern/lib/win32/microsoft" -lmclmcrrt


It gets compiled in QT 4.7.3. But in QT 5 it is not able to find the symbols for MCR library functions.
D:\QT\DCC_TuningTool\plugins\MTF\MTF.cpp:50: error: undefined reference to `mxCreateDoubleScalar_proxy(double)'
D:\QT\DCC_TuningTool\plugins\MTF\MTF.cpp:51: error: undefined reference to `mxCreateDoubleScalar_proxy(double)'
D:\QT\DCC_TuningTool\plugins\MTF\MTF.cpp:52: error: undefined reference to `mxCreateDoubleScalar_proxy(double)'
D:\QT\DCC_TuningTool\plugins\MTF\MTF.cpp:55: error: undefined reference to `mxCreateString_proxy(char const*)'

and so on..

all these symbols exist on mclmcrrt.lib

If I do a static linking

DEFINE += static
it gets compiled. But I need dynamic linking for this plug in.

I have other plug-ins, where I don't have the any CPP source file, there static/dynamic both linking works.

ChrisW67
29th July 2013, 21:36
Line 23 is missing a hyphen.

subhagato
30th July 2013, 09:05
Hi Chris,

Thanks for your answer, but I am sorry, I can't find any missing hyphen on line 23.


LIBS += -L"C:/Program Files/MATLAB/MATLAB Compiler Runtime/v713/extern/lib/win32/microsoft" -lmclmcrrt


My MTF.cpp file is



#include "MTF.h"

int MaxX = 255;


Chart * chart;
Chart::Chart(PluginAnalysisIO * IO): QObject(IO)
{
pluginIO = IO;
// return;
//QWidget * parentWidget = pluginIO->outputWidgets[0];

// QVBoxLayout *layout1 = new QVBoxLayout(parentWidget);
// layout1->addWidget(plot);
// QGridLayout * grid = new QGridLayout(parentWidget);
// layout1->addLayout(grid);
// if(!LibTI_MTFInitializeWithHandlers(DefaultErrorHa ndler, DefaultPrintHandler)) {
if(!LibTI_MTFInitialize()){
//mclTerminateApplication();
QMessageBox::critical(0,"Error", "Error initializing Matlab engine!\nPlease try to restart application.");
//return 2;
} else{
//return 0;
}
}

int main(int a,char** ){ return 0;}

Chart::~Chart(){
LibTI_MTFTerminate();
}



void Chart::showChart(){

QString imageFileName = pluginIO->imageFileName.toLower();
QDir tempDir(QDir::tempPath());
// QString tempPath = tempDir.canonicalPath();
QString tempPath = tempDir.absolutePath();

QString outPrefix = tempPath+"/MTF_Images_";
QString CoordinatesFile = outPrefix + "coordinates.txt";
#if defined(Q_OS_WIN)
outPrefix.replace("/","\\");
imageFileName.replace("/","\\");
CoordinatesFile.replace("/","\\");
#endif

mxArray * cols = mxCreateDoubleScalar(pluginIO->rawWidth);
mxArray * rows = mxCreateDoubleScalar(pluginIO->rawHeight);
mxArray * phase = mxCreateDoubleScalar(pluginIO->rawColorPattern);
mxArray * dcsub = mxCreateDoubleScalar(0);
mxArray * R = NULL;
mxArray * infilename = mxCreateString(imageFileName.toStdString().c_str() );
mxArray * rotate = mxCreateDoubleScalar(0);
mxArray * figurePref = mxCreateString(outPrefix.toStdString().c_str());
mxArray * filename_coords = mxCreateString(CoordinatesFile.toStdString().c_str ());
QFile::remove(pluginIO->fileNames[0]);
QFile::remove(pluginIO->fileNames[1]);
pluginIO->fileNames[0] = "";
pluginIO->fileNames[1] = "";

FILE* coordinates = fopen(CoordinatesFile.toStdString().c_str(),"w");
if (coordinates != NULL){
fprintf(coordinates,"%d, %d, %d, %d\r\n",pluginIO->selectedRect.topLeft().x(), pluginIO->selectedRect.bottomRight().x(),pluginIO->selectedRect.topLeft().y(), pluginIO->selectedRect.bottomRight().y());
fclose(coordinates);
if (imageFileName.endsWith(".raw",Qt::CaseInsensitive)|| imageFileName.endsWith(".rawle",Qt::CaseInsensitive)){
mlfRawmtfse(1, &R, infilename, cols, rows, phase, dcsub, figurePref, filename_coords);
} else
if (imageFileName.endsWith(".jpg",Qt::CaseInsensitive)|| imageFileName.endsWith(".bmp",Qt::CaseInsensitive)||imageFileName.endsWith(".jpeg",Qt::CaseInsensitive)){
mlfImgmtfse(1, &R, infilename, rotate, figurePref, filename_coords);

} else {
QMessageBox::critical(0,"Error", tr("Improper image type selected! \nAcceptable file extensions are: \n *.jpg, *.bmp, *.raw, *.rawLE") );
goto end;//-->
}

if (R == NULL){
QString parameters = "\nFile = " + QString(mxArrayToString(infilename));
parameters += " \nfigurePref = " + QString(mxArrayToString(figurePref));
parameters += " \nfilename_coords = " + QString(mxArrayToString(filename_coords));
parameters += " \ncols = " + QString::number(* mxGetPr(cols));
parameters += " \nrows = " + QString::number(* mxGetPr(rows));
parameters += " \nphase = " + QString::number(* mxGetPr(phase));
parameters += " \ndcsub = " + QString::number(* mxGetPr(dcsub));
QFile coordinates_txt(CoordinatesFile);
coordinates_txt.open(QIODevice::ReadOnly);
QString coords(coordinates_txt.readAll());
coordinates_txt.close();
parameters += "\nRect: "+ coords;
QMessageBox::critical(0,"Error", tr("MatLab returned error!") + parameters);
}else
if (* mxGetPr(R) != -1){
pluginIO->fileNames[0] = outPrefix+"figure_1.jpeg";
pluginIO->fileNames[1] = outPrefix+"figure_2.jpeg";
mxDestroyArray(R);
}
else if (* mxGetPr(R) == -1){
QMessageBox::critical(0,"Error", tr("Cannot evaluate function! \nPlease try selecting another area!"));
}
else QMessageBox::critical(0,"Error", tr("Unrecognized error!"));
} else {
QMessageBox::critical(0,"Error",tr("Error creating coordinates file: ") + CoordinatesFile);
}
end:
mxDestroyArray(infilename);
mxDestroyArray(rotate);
mxDestroyArray(figurePref);
mxDestroyArray(filename_coords);

}

extern "C"
{
MTFSHARED_EXPORT int init(PluginAnalysisIO * IO){
chart = new Chart(IO);
return 0;
}

MTFSHARED_EXPORT void show(){
chart->showChart();
}
}

int DefaultPrintHandler(const char *s)
{
return strlen(s);//->
return mclWrite(1 /* stdout */, s, sizeof(char)*strlen(s));
}

int DefaultErrorHandler(const char *s)
{
int written = 0;
size_t len = 0;
len = strlen(s);

return len;//->
written = mclWrite(2 /* stderr */, s, sizeof(char)*len);
if (len > 0 && s[ len-1 ] != '\n')
written += mclWrite(2 /* stderr */, "\n", sizeof(char));
return written;
}