Unable to compile using "mex fmpc_sim.c libmwblas.lib libmwlapack.lib" undefined reference to '_dgemm_'

10 ビュー (過去 30 日間)
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.

採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 23 日
mex -Ddgemm_=dgemm fmpc_sim.c -lmwblas -lmwlapack
or
mex -D_dgemm=dgemm fmpc_sim.c -lmwblas -lmwlapack
depending which side the underscore is showing up on. Repeat similar -D for the other symbols.
  6 件のコメント
Debashish Mohapatra
Debashish Mohapatra 2018 年 1 月 10 日
Same here. The library was compiled after adding the recommended definitions by James Tursa, and can be successfully compiled by following the suggestions made by Walter Roberson i.e.
mex -D_dgemm=dgemm fmpc_sim.c -lmwblas -lmwlapack
However, running the given examples with the library crashes MATLAB.
Bernardo Hernandez
Bernardo Hernandez 2019 年 6 月 20 日
編集済み: Bernardo Hernandez 2019 年 6 月 20 日
Same problem here. I tried James Tursa's answer and it compiles without problems. But then, MATLAB simply closes when I try to run the examples.
I also compiled it on Linux, which was possible without any modification of the original files. This further confirms that the issue is due to function calling style. Nevertheless, when I called the linux-compiled functions MATLAB also crashed.
Has anyone found a solution to this?

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

その他の回答 (1 件)

James Tursa
James Tursa 2016 年 10 月 23 日
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 件のコメント
Ankitkumar Maddewad
Ankitkumar Maddewad 2021 年 3 月 1 日
Facing similar issue. How can we resolve the issue of MATLAB crashing?
Thanks in advance.
rupal
rupal 2023 年 3 月 16 日
have any one solved this issue if yes than how ?

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

カテゴリ

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