I generated *.dll
dynamic-link library file by compiling the application I developed in MATLAB using MRC (MATLAB Runtime Compiler). I'm using the MSVC compiler and qmake toolset in the Qt Creator environment to distribute and/or use the procedures in the application I developed in MATLAB in the Windows OS environment. But I'm having trouble adding the dynamic-link libraries (for example mclmcrrt.lib
, libmx.lib
, libmex.lib
, libmat.lib
, libfixedpoint.lib
, etc.) shared by the MATLAB Runtime Compiler to my project. When I build the project in the Qt Creator environment, I get the following error:
* LNK1104: cannot open file 'mclmcrrtd.lib'
* U1077: "\VS\Tools\MSVC\{Version}\bin\HostX86\x64\link.EXE": return code '0x450'
* U1077: "\VS\Tools\MSVC\{Version}\bin\HostX86\x64\nmake.exe": return code '0x2'
How do I solve this problem?
CodePudding user response:
1. Definition of Error
I tested this bug by starting a similar project. When I compile the project in Qt Creator I got the following error:
LNK1104: cannot open file 'mclmcrrtd.lib'
2. Steps To Fix The Error
Follow the steps below to fix the problem:
- I didn't add dependencies manually in QT Creator. I added a dynamic library by right-clicking on the project name and going to
Add Library > External Library
. I used the following settings in the External Library window in QT Creator, I added files and directories using these settings:
* Linkage: Dynamic
* Mac: Library
* [✔] Library inside "debug" or "release" subfolder
* [ ] Add "d" suffix for debug version
* [ ] Remove "d" suffix for release version
- I examined how the window opened in the second step transfers information about the dynamic library to the *.pro file. I selected the
mclmcrrt.lib
file in the~/lib/win64/
directory and clicked the Next button in the External Library window on Qt Creator. I saw that themclmcrrt.lib
library was named differently in Win32, Win64 and Unix systems when imported to Qt Creator in this way (likelmclmcrrt
,lmclmcrrtd
,lmclmcrrt
).
win32:CONFIG(release, debug|release): LIBS = -L$$PWD/'../../../../Program Files/MATLAB/R2018B/extern/lib/win64/microsoft/' -lmclmcrrt
else:win32:CONFIG(release, debug|release): LIBS = -L$$PWD/'../../../../Program Files/MATLAB/R2018B/extern/lib/win64/microsoft/' -lmclmcrrtd
else:unix: LIBS = -L$$PWD/'../../../../Program Files/MATLAB/R2018B/extern/lib/win64/microsoft/' -lmclmcrrt
INCLUDEPATH = $$PWD/'../../../../Program Files/MATLAB/R2018B/extern/lib/win64/microsoft'
DEPENDPATH = $$PWD/'../../../../Program Files/MATLAB/R2018B/extern/lib/win64/microsoft'
- This is how I learned how to properly import files and directories into my project file. I added all the requirements manually myself; I didn't use the interface to avoid file and directory confusion.
win32:CONFIG(release, debug|release): LIBS = -L$$PWD/'../../../../Program Files/MATLAB/R2018B/extern/lib/win64/microsoft/' -lmclmcrrt
else:win32:CONFIG(release, debug|release): LIBS = -L$$PWD/'../../../../Program Files/MATLAB/R2018B/extern/lib/win64/microsoft/' -lmclmcrrtd
else:unix: LIBS = -L$$PWD/'../../../../Program Files/MATLAB/R2018B/extern/lib/win64/microsoft/' -lmclmcrrt
INCLUDEPATH = $$PWD/'../../../../Program Files/MATLAB/R2018B/extern/include'
INCLUDEPATH = $$PWD/'../../../../Program Files/MATLAB/R2018B/extern/include/win64'
INCLUDEPATH = $$PWD/'../../../../Program Files/MATLAB/R2018B/extern/lib/win64/microsoft'
DEPENDPATH = $$PWD/'../../../../Program Files/MATLAB/R2018B/extern/lib/win64/microsoft'
- When using the
Build > Rebuild All Projects
command in Qt Creator to compile the project, I got the errorLNK1104: Cannot open file 'mclmcrrtd.lib'
again. I found out that this is because the old MATLAB Compiler Runtime (MCR) is only suitable for x86 architecture. For this reason, I discovered that many sample QT-Matlab Compiler Runtime projects on the internet use thewin32
tag in the descriptions in *.pro files. However, I thought it would not be correct to use thewin32
tag because of the phraseHostX64\x64
when called from theC:\Program Files(x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\{Version}\bin\HostX64\x64\cl.exe
directory of the current MSVC. The final configuration in the *.pro file containing the relevant code block is as follows and successfully
LIBS = -L$$PWD/'../../../../Program Files/MATLAB/R2018B/extern/lib/win64/microsoft/' -lmclmcrrt
INCLUDEPATH = $$PWD/'../../../../Program Files/MATLAB/R2018B/extern/include'
INCLUDEPATH = $$PWD/'../../../../Program Files/MATLAB/R2018B/extern/include/win64'
INCLUDEPATH = $$PWD/'../../../../Program Files/MATLAB/R2018B/extern/lib/win64/microsoft'
DEPENDPATH = $$PWD/'../../../../Program Files/MATLAB/R2018B/extern/lib/win64/microsoft'