Cplex linking Error in Mex Command from Matlab - mex

I am trying to run mixed integer quadratic programming by calling Cplex (122version) from Matlab using Mex function. When I try in matlab : mex miqp_cplex.c, following type errors occurred.
Creating library C:\Users\maskamal\AppData\Local\Temp\mex_3XVWAG\templib.x and object C:\Users\maskamal\AppData\Local\Temp\mex_3XVWAG\templib.exp
miqp_cplex.obj : error LNK2019: unresolved external symbol __imp_CPXcloseCPLEX referenced in function miqp
miqp_cplex.obj : error LNK2019: unresolved external symbol __imp_CPXfreeprob referenced in function miqp
miqp_cplex.obj : error LNK2019: unresolved external symbol __imp_CPXgetmipitcnt referenced in function miqp
miqp_cplex.mexw64 : fatal error LNK1120: 21 unresolved externals
C:\PROGRA~1\MATLAB\R2011A\BIN\MEX.PL: Error: Link of 'miqp_cplex.mexw64' failed.
Since it fail to locate "ilcplex\cplex.h", I add full path
include "C:\ILOG\CPLEX_Studio_AcademicResearch122\cplex\include\ilcplex\cplex.h" and I guess problem is related to cplex.h and linking with library.
Any hints to solve my problem are welcomed.

I could solve it partly. I could compile by adding the path of library with mex command. However, when I run the mex file: miqp_cplex it says:
Invalid MEX-file 'C:\Users\maskamal\Documents\MATLAB\MexCplex80\miqp_cplex.mexw64': 指定されたモジュールが見つかりません。(translation from japanese: indicated module is not found)
My Matlab R2011a and Cplex122

Related

MKL Linker error with some PARDISO subroutines

Some, but not all:
error LNK2019: unresolved external symbol PARDISO_CHKMATRIX_Z referenced in function GCS_SYSTEMSOLVE_mp_PARDISOSPARSESOLVER
error LNK2019: unresolved external symbol PARDISO_CHKVEC_Z referenced in function GCS_SYSTEMSOLVE_mp_PARDISOSPARSESOLVER
error LNK2019: unresolved external symbol PARDISO_PRINTSTATS_Z referenced in function GCS_SYSTEMSOLVE_mp_PARDISOSPARSESOLVER
The PARDISO solver call itself works fine. Actually, the subroutine calls are made in a project which itself can be compiled correctly. It is an exe project (a unit test project) that makes calls to that lib that pops up these linker errors.
I am using Intel Parallel Studio 2017. According to the Intel Linker Tool, everything should be in good order, although apparently I must be missing something.

How should I deal with "Fatal error LNK1120" when I tried to compile Ipopt-3.9.3 in Windows 10 & Visual C++ 2010

all.
I’m compiling Ipopt-3.9.3 in Windows 10 & Visual C++ 2010 Express.
I’ve built the projects of libCoinBlas, libConHSL, libCoinLapack as well as libIpopt, and generated libCoinBlas.lib, libCoinHSL.lib, libCoinLapack.lib as well as libIpopt.lib in the correct paths but with some warnings.
While when I tried to build the projects of IpoptAmplSolver and hs071_cpp, there exists the following fatal errors.
5>  Generating Code...
5> Creating library Release\IpoptAmplSolver.lib and object Release\IpoptAmplSolver.exp
5>dlarf.obj : error LNK2019: unresolved external symbol _iladlr_ referenced in function _dlarf_
5>dlarfb.obj : error LNK2001: unresolved external symbol _iladlr_
5>dlarf.obj : error LNK2019: unresolved external symbol _iladlc_ referenced in function _dlarf_
5>dlarfb.obj : error LNK2001: unresolved external symbol _iladlc_
5>dlascl.obj : error LNK2019: unresolved external symbol _disnan_ referenced in function _dlascl_
5>dpotf2.obj : error LNK2001: unresolved external symbol _disnan_
5>Release\IpoptAmplSolver.exe : fatal error LNK1120: 3 unresolved externals
========== Rebuild All: 4 succeeded, 1 failed, 0 skipped ==========
5>------ Rebuild All started: Project: hs071_cpp, Configuration: Release Win32 ------
5>  hs071_main.cpp
5>  hs071_nlp.cpp
5>  Generating Code...
5>dlarf.obj : error LNK2019: unresolved external symbol _iladlr_ referenced in function _dlarf_
5>dlarfb.obj : error LNK2001: unresolved external symbol _iladlr_
5>dlarf.obj : error LNK2019: unresolved external symbol _iladlc_ referenced in function _dlarf_
5>dlarfb.obj : error LNK2001: unresolved external symbol _iladlc_
5>dlascl.obj : error LNK2019: unresolved external symbol _disnan_ referenced in function _dlascl_
5>dpotf2.obj : error LNK2001: unresolved external symbol _disnan_
5>LIBCMT.lib(wincrt0.obj) : error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup
5>Release\hs071_cpp.exe : fatal error LNK1120: 4 unresolved externals
========== Rebuild All: 4 succeeded, 1 failed, 0 skipped ==========
Is there anyone who can kindly tell me how should I deal with it?
Thank you very much for your attention, and I’m looking forward to your kind aid.
Finally, I've solved this problem which is due to the undefined functions. I think my case is about a released software package rather than some specific procedure code, hence, it's a little different and relative simple.
Without knowing the specifics of the libraries you are using, I recommend that you try the following to deal with this error:
The error tells you that the linker is missing code for some function calls. This probably means that a library file is not found. Make sure that the linker can find all needed lib files. Check the property pages. Under the Linker->General->Additional library directories, make sure that the directories where your lib-files are located are present and under Linker->Input->Additional dependencies, make sure that the the lib-files are listed. Also make sure that the parameters are present for the different Configurations.
If this still does not help, check if your libraries depend on other libraries. These should be mentioned in the documentation of the libraries you are using.
I've not built this, but here's what I would try from the start. From what you've said, you've compiled the .lib files that it links against and it's failing during linking.
So here are your options...
1) You've either missed a .lib file in the input list for the linker.
2) The actual .lib file doesn't contain the symbol that the linker needs (you can check this by dumping the symbols of the .lib file)
3) Your .lib file is compiled with either the wrong platform than what you're linking with or with the wrong type ie. release/debug.
4) The symbols in your lib are decorated because you're compiling as C++ instead of C, or visa-versa.
If you go through the above steps above, I'm pretty sure you'll find your problem, but you've not really given enough information to properly answer your question. Personally, I'd have a guess that you're compiling C as C++ or you've got the wrong platform type set for one of your lib files.
Thank you all very much for your patient and detailed advices that inspired me, and I finally find out that I should add some C files which define the necessary functions into my project. The detailed solution is as follows.
For example, I want to eliminate
5>dlarf.obj : error LNK2019: unresolved external symbol _iladlr_ referenced in function _dlarf_
5>dlarfb.obj : error LNK2001: unresolved external symbol _iladlr_
Step 1: Run
f2c iladlr.f
In the Visual Stuido Command Prompt and generate iladlr.c.
Step 2: Add iladlr.c to my project.
Step 3: Rebuild.
Finally, everything goes well.

unresolved external symbol inflateEnd (and others) while using boost Zlib

I'm in the process of converting 32bit project to x64. In most cases it just means appending 64 to library paths (and eventually building those libraries for x64). Now I assume all libraries are already ready and the code is also x64 compatible. But I keep getting errors for boost zlib library, like these:
error LNK2019: unresolved external symbol inflateEnd
error LNK2019: unresolved external symbol inflate
error LNK2019: unresolved external symbol inflateInit_
error LNK2019: unresolved external symbol deflateEnd
error LNK2019: unresolved external symbol deflate
error LNK2001: unresolved external symbol "int const boost::iostreams::zlib::default_compression"
error LNK2001: unresolved external symbol "int const boost::iostreams::zlib::deflated"
error LNK2001: unresolved external symbol "int const boost::iostreams::zlib::default_strategy"
I enabled verbose mode for linker (in MS Visual Studio you do this by adding /VERBOSE:LIB to additional linker options). Thanks to that, I can see this output line:
Searching .\..\..\libs\boost145\stage\lib64\libboost_zlib-vc100-mt-gd-1_45.lib
That would imply that the library was found in the boost145\stage\lib64. So what should I be looking for now?
One strange thing is that file that defines the first group of missing symbols (those that are not within boost) has header files within the project, zlib.h and zconf.h. Maybe this is some hint? The zlib.h defines external symbols as:
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
Obvious question is: where the hell is lib file for this header file?
I had the same issue, to resolve the errors I download the source from zlib and built the x64 dlls/libs locally. There were a couple issues with solution file downloaded, fixes are described below.
Zlib 1.2.8 source code: http://zlib.net/zlib128.zip
Solution File for VS2012 is located at: zlib-1.2.8\contrib\vstudio\vc11\zlibvc.sln
Fixes:
Change:
<Command>cd ..\..\..\contrib\masmx64
bld_ml64.bat</Command>
to:
<Command>cd ..\..\contrib\masmx64
bld_ml64.bat</Command>
In zlibvc project properties -> Linker -> Advanced -> Image Has Safe Exception Handlers -> set to No (/SAFESEH:NO). Info about SAFESEH: Compiling libffi with VS2012 fails with fatal error LNK1281: Unable to generate SAFESEH image

How to save matlab trained model in libsvm

I'm new to libsvm and matlab. I have downloaded libsvm 3.17 from the web site and trained my dataset using Matlab. I wanted to save the file and I used svm_savemodel.c which refused to compile in matlab. This is the message that I get
mex svm_savemodel.c
Creating library C:\Users\mark\AppData\Local\Temp\mex_zcr67j\templib.x and object C:\Users\mark\AppData\Local\Temp\mex_zcr67j\templib.exp
svm_savemodel.obj : error LNK2019: unresolved external symbol _svm_free_and_destroy_model referenced in function _mexFunction
svm_savemodel.obj : error LNK2019: unresolved external symbol _svm_save_model referenced in function _mexFunction
svm_savemodel.obj : error LNK2019: unresolved external symbol _matlab_matrix_to_model referenced in function _mexFunction
svm_savemodel.mexw32 : fatal error LNK1120: 3 unresolved externals
C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: Link of 'svm_savemodel.mexw32' failed.
Error using mex (line 206)
Unable to complete successfully.
So can anyone help me to solve this?
I have included svm.h, mex.h, svm_model_matlab.h but it refused....
This is what I have done
>> mex -setup
Welcome to mex -setup. This utility will help you set up
a default compiler. For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2011b/win32.html
Please choose your compiler for building MEX-files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler:
[1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2011b\sys\lcc
[2] Microsoft Visual C++ 2010 in C:\Program Files\Microsoft Visual Studio 10.0
[0] None
Compiler: 2
Please verify your choices:
Compiler: Microsoft Visual C++ 2010
Location: C:\Program Files\Microsoft Visual Studio 10.0
Are these correct [y]/n? y
***************************************************************************
Warning: MEX-files generated using Microsoft Visual C++ 2010 require
that Microsoft Visual Studio 2010 run-time libraries be
available on the computer they are run on.
If you plan to redistribute your MEX-files to other MATLAB
users, be sure that they have the run-time libraries.
***************************************************************************
Trying to update options file: C:\Users\michael\AppData\Roaming\MathWorks\MATLAB\R2011b\mexopts.bat
From template: C:\PROGRA~1\MATLAB\R2011b\bin\win32\mexopts\msvc100opts.bat
Done . . .
**************************************************************************
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the new
API. You can find more information about this at:
http://www.mathworks.com/support/solutions/en/data/1-5C27B9/?solution=1-5C27B9
Building with the -largeArrayDims option enables the new API.
**************************************************************************
>> cd('C:\libsvm-3.17\libsvm-3.17\matlab');
>> make
>> mex svm_savemodel.c
Creating library C:\Users\michael\AppData\Local\Temp\mex_coX2K1\templib.x and object C:\Users\michael\AppData\Local\Temp\mex_coX2K1\templib.exp
svm_savemodel.obj : error LNK2019: unresolved external symbol _svm_free_and_destroy_model referenced in function _mexFunction
svm_savemodel.obj : error LNK2019: unresolved external symbol _svm_save_model referenced in function _mexFunction
svm_savemodel.obj : error LNK2019: unresolved external symbol _matlab_matrix_to_model referenced in function _mexFunction
svm_savemodel.mexw32 : fatal error LNK1120: 3 unresolved externals
C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: Link of 'svm_savemodel.mexw32' failed.
Error using mex (line 206)
Unable to complete successfully.
>>
add this to your make.m file (you can add them to both if and else part):
mex CFLAGS="$CFLAGS -std=c99" -largeArrayDims svm_savemodel.c ../svm.cpp svm_model_matlab.c

Installing GLFW 3.0 not working Visual Studio

I'm trying to create a GLFW project, but I'm getting LNK2019 errors with the basic setup.
I've downloaded the latest binary (glfw-3.0.bin.WIN32.zip) to a folder.
I've created a new, empty console project.
Within VC++ Directories, I've added the following line to include directories:
C:\C++Libraries\glfw-3.0.bin.WIN32\include
I've added the following line to the Library Directories:
C:\C++Libraries\glfw-3.0.bin.WIN32\lib-msvc110
I've linked the following libraries:
opengl32.lib, glfw3.lib, glfw3dll.lib
From the latest tutorial, I paste into my project (no visible syntax errors) to test, but I get four LNK2019 errors after trying to run it.
Here are the errors:
Error 2 error LNK2019: unresolved external symbol __imp__joyGetPosEx#8
referenced in function __glfwPlatformGetJoystickAxes
c:\Users\Spicy Weenie\documents\visual studio 2012\
Projects\Beta\Beta\glfw3.lib(win32_joystick.obj)
Error 3 error LNK2019: unresolved external symbol __imp__joyGetDevCapsW#12
referenced in function __glfwPlatformGetJoystickAxes
c:\Users\Spicy Weenie\documents\visual studio
2012\Projects\Beta\Beta\glfw3.lib(win32_joystick.obj)
Error 4 error LNK2019: unresolved external symbol __imp__joyGetPos#8
referenced in function __glfwPlatformJoystickPresent
c:\Users\Spicy Weenie\documents\visual studio
2012\Projects\Beta\Beta\glfw3.lib(win32_joystick.obj)
Error 1 error LNK2019: unresolved external symbol __imp__timeGetTime#0
referenced in function __glfwInitTimer c:\Users\Spicy Weenie\documents\visual
studio 2012\Projects\Beta\Beta\glfw3.lib(win32_time.obj)
You need to link in at least winmm.lib for timeGetTime. The joystick code is probably in there to.