Unable to compile using "mex fmpc_sim.c libmwblas.lib libmwlapack.lib" undefined reference to '_dgemm_'
Show older comments
I am having the exact same problem as https://www.mathworks.com/matlabcentral/answers/172057-error-using-mex-line-206-unable-to-complete-successfully
I installed matlab2011a (32 bit) in windows10 (64bit).
I tried to install Fast Model Predictive Control Using Online Optimization from http://stanford.edu/~boyd/fast_mpc/ which contain a Mex solver. During the setup step, I am supposed to compile a c file fmpc.c using
mex fmpc_sim.c libmwblas.lib libmwlapack.lib
But for whatever reason, it says there are a bunch of undefined references. I have followed the instructed nearly exactly as stated, what could be going wrong? How do I solve this reference error?
EDU>> 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/R2011a/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~2\MATLAB\R2011A~1\sys\lcc
[0] None
Compiler: 1
Please verify your choices:
Compiler: Lcc-win32 C 2.4.1
Location: C:\PROGRA~2\MATLAB\R2011A~1\sys\lcc
Are these correct [y]/n? y
Trying to update options file: C:\Users\n\AppData\Roaming\MathWorks\MATLAB\R2011a\mexopts.bat
From template: C:\PROGRA~2\MATLAB\R2011A~1\bin\win32\mexopts\lccopts.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.
**************************************************************************
EDU>> mex fmpc_sim.c libmwblas.lib libmwlapack.lib
Writing library for fmpc_sim.mexw32
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_dgemm_'
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_dposv_'
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_dgemv_'
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_daxpy_'
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_dtrtrs_'
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_dtrsv_'
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_dnrm2_'
C:\PROGRA~2\MATLAB\R2011A~1\BIN\MEX.PL: Error: Link of 'fmpc_sim.mexw32' failed.
??? Error using ==> mex at 208
Unable to complete successfully.
Installation instructions for fast_mpc -----------------------------------------------------------------------
fast_mpc is written in C with a mex interface to MATLAB. Before installation, make sure that BLAS and LAPACK libraries are installed in your machine.
1. Unpack the fast_mpc files, or get them individually.
2. Start MATLAB and cd to the directory containing the source files.
3. At the MATLAB command prompt type
>> mex -setup
and enter the number corresponding to the template option gccopts.sh.
4. Compile fmpc_sim.c using
>> mex fmpc_sim.c
On some machines you may need to specify the libraries
>> mex fmpc_sim.c -lblas -llapack
If you want to link your own libraries, you can. For example,
to link the libraries libacml.a, libacml_mv.a, and libgfortran.a
in the directory /opt/acml/lib, use the option '-L' to specify the
library search path and the option '-l' to specify the individual
libraries, as in
>> mex fmpc_sim.c -L/opt/acml/lib -lacml -lacml_mv -lgfortran
5. If fmpc_sim.c compiles successfully, do the same with fmpc_step.c.
6. Test the installation by running the masses_example script
>> masses_example
which will run MPC, for 100 iterations, on the masses example in the paper,
using mpc_step. You should see reports from each iteration printed to your
screen. The last one, for example, should look like
iteration step rd rp
0 0.3874 1.09294e+01 1.27108e+00
1 1.0000 1.54052e+00 1.39748e-14
2 1.0000 2.98332e-01 1.40216e-15
3 1.0000 1.16741e-02 1.02482e-15
The average cost is: 5.683200
Test mpc_sim by running the script randsys_example.
Accepted Answer
More Answers (1)
James Tursa
on 23 Oct 2016
Looks like the source code you are using was intended for UNIX machines. In particular these errors:
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_dgemm_'
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_dposv_'
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_dgemv_'
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_daxpy_'
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_dtrtrs_'
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_dtrsv_'
c:\users\n\appdata\local\temp\mex_89dw4r\fmpc_sim.obj .text: undefined reference to '_dnrm2_'
The extra underscore _ at the end of the BLAS library names indicate UNIX convention names, but you are compiling on a Windows machine and these trailing underscores are not present in the names in the Windows versions of these libraries. The solution is simply to get rid of those extra underscores at the end of these names since they are not present in the Windows library versions. You could edit your code to change all of these names, or maybe all it will take is to put something like this in your code so it will use the correct names in either version:
#if defined(__OS2__) || defined(__WINDOWS__) || defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) || defined(_MSC_VER)
#define dgemm_ dgemm
#define dposv_ dposv
#define dgemv_ dgemv
#define daxpy_ daxpy
#define dtrtrs_ dtrtrs
#define dtrsv_ dtrsv
#define dnrm2_ dnrm2
#endif
4 Comments
Bernardo Hernandez
on 24 Jun 2019
Dear James,
Following your advice I was able to compile, however when I try to execute the compiled file MATLAB crashes. I changed to MATLAB running natively in Ubuntu, where as expected I did not need to add the lines you proposed in order to compile correctly. Nevertheless, running the compiled function results in MATLAB crashing.
After further investigation I was able to note that it is the "F77_call(?)" lines of code that generate the crash (where ? is any of dgemm, dposv, etc). That is, if I comment them out, the "*.c" function not only compiles properly, but also runs without crashing when called in MATLAB. Do you have any idea why could this be the case? Should I post some of the code on the "*.c" function for my question to be more understandable?
Kind regards,
Nerea Urbina
on 21 Mar 2020
Dear Bernardo,
I can't fix the error so, could you give more information? I don't understand the reference to "F77_call"
Thanks in advance
Ankitkumar Maddewad
on 1 Mar 2021
Facing similar issue. How can we resolve the issue of MATLAB crashing?
Thanks in advance.
rupal
on 16 Mar 2023
have any one solved this issue if yes than how ?
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!