Undefined symbols for architecture x86_64 error. Mex S-Function

8 views (last 30 days)
Okay, so I am far from an experienced coder, and am helping my professor with a project. I received a collection of MATLAB functions that are represented in Simulink. I had to create new mex files, which I thought worked at first, but when I would run it through Simulink, I was coming up with an "invalid sizes vector" error (block error). The original code is in c, and I'm using Visual Studios as my compiler. The c-code is an S-function within Simulink as well. After researching a bit, I found that I had to add
#ifdef MATLAB_MEX_FILE
#include "simulink.c"
#else
#include "cg_sfun.h"
#endif
to the end of all mex S-functions. Once I did this, I tried re-creating the mex files and got this error:
>> mex Core_Neutronics.c
Undefined symbols for architecture x86_64:
"_dgesvd_", referenced from:
_mdlOutputs in Core_Neutronics.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mex: link of ' "Core_Neutronics.mexmaci64"' failed.
Error using mex (line 206)
Unable to complete successfully.
------------------------------------------------ ------------------------------------------------
My code consists of two lines where dgesv is used.
/* DGESV prototype */
extern void dgesv_( int* n, int* nrhs, double* a, int* lda, int* ipiv, double* b, int* ldb, int* info);
Then later,
dgesv(&matrix_size, &brnhs, a, &matrix_size, ipvt, b, &matrix_size, &info);
I notice that there is an underscore in the first line, but not later on in the second. Even when this is changed, the same error still occurs. Does anyone know what's going on? I know that I don't have a bunch of detail for my code, but I was hoping someone could point me in the right direction. Also, I do have these libraries called out in Matlab
/* C Header for the Simulink interface */
#include "simstruc.h"
/* Other C Headers */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <math.h>
Could it be that I don't have these libraries installed somehow? (If not, how do I install these?)

Answers (1)

Muruganandham Subramanian
Muruganandham Subramanian on 20 Feb 2014
Try using
dgesv(matrix_size, brnhs, a, matrix_size, ipvt, b, matrix_size, info);
Because, when you are passing as an pointer variable, it processes the address
  1 Comment
Ryan Byrne
Ryan Byrne on 26 Feb 2014
Thanks for the response. Unfortunately, I still get a similar error.
When I use dgesv() I get the following error:
>> mex Core_Neutronics.c
Core_Neutronics.c:559:2: warning: implicit declaration of function 'dgesv' is invalid in
C99 [-Wimplicit-function-declaration]
dgesv(matrix_size, brnhs, a, matrix_size, ipvt, b, matrix_size, info);
^
1 warning generated.
Undefined symbols for architecture x86_64:
"_dgesv", referenced from:
_mdlOutputs in Core_Neutronics.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mex: link of ' "Core_Neutronics.mexmaci64"' failed.
__________________________________________________________
when I used dgesv_(), I get a long, long error regarding an incompatible integer to pointer conversion:
>> mex Core_Neutronics.c
Core_Neutronics.c:559:9: warning: incompatible integer to pointer conversion passing 'int'
to parameter of type 'int *'; take the address with & [-Wint-conversion]
dgesv_(matrix_size, brnhs, a, matrix_size, ipvt, b, matrix_size, info);
^~~~~~~~~~~
&
Core_Neutronics.c:112:26: note: passing argument to parameter 'n' here
extern void dgesv_( int* n, int* nrhs, double* a, int* lda, int* ipiv, double* b, ...
^
Core_Neutronics.c:559:22: warning: incompatible integer to pointer conversion passing
'int' to parameter of type 'int *'; take the address with & [-Wint-conversion]
dgesv_(matrix_size, brnhs, a, matrix_size, ipvt, b, matrix_size, info);
^~~~~
&
Core_Neutronics.c:112:34: note: passing argument to parameter 'nrhs' here
extern void dgesv_( int* n, int* nrhs, double* a, int* lda, int* ipiv, double* b, ...
^
Core_Neutronics.c:559:32: warning: incompatible integer to pointer conversion passing
'int' to parameter of type 'int *'; take the address with & [-Wint-conversion]
dgesv_(matrix_size, brnhs, a, matrix_size, ipvt, b, matrix_size, info);
^~~~~~~~~~~
&
Core_Neutronics.c:112:56: note: passing argument to parameter 'lda' here
extern void dgesv_( int* n, int* nrhs, double* a, int* lda, int* ipiv, double* b, ...
^
Core_Neutronics.c:559:54: warning: incompatible integer to pointer conversion passing
'int' to parameter of type 'int *'; take the address with & [-Wint-conversion]
dgesv_(matrix_size, brnhs, a, matrix_size, ipvt, b, matrix_size, info);
^~~~~~~~~~~
&
Core_Neutronics.c:112:88: note: passing argument to parameter 'ldb' here
...int* n, int* nrhs, double* a, int* lda, int* ipiv, double* b, int* ldb, int* info);
^
Core_Neutronics.c:559:67: warning: incompatible integer to pointer conversion passing
'int' to parameter of type 'int *'; take the address with & [-Wint-conversion]
dgesv_(matrix_size, brnhs, a, matrix_size, ipvt, b, matrix_size, info);
^~~~
&
Core_Neutronics.c:112:98: note: passing argument to parameter 'info' here
...n, int* nrhs, double* a, int* lda, int* ipiv, double* b, int* ldb, int* info);
^
5 warnings generated.
Undefined symbols for architecture x86_64:
"_dgesv_", referenced from:
_mdlOutputs in Core_Neutronics.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mex: link of ' "Core_Neutronics.mexmaci64"' failed.
Error using mex (line 206)
Unable to complete successfully.
>>

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!