Mex Link Failure: Undefined Symbols for Architecture
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am using Mac OS X 10.9, and Matlab 2013a, I'm compiling with Xcode 5.1.1 (I think, I don't know how to check). I have edited my mexopts.sh file to update all instances of 10.7 to 10.9. Now I'm getting a linker error that I see a lot of people have gotten before, however based on the answers to all the previous posts I have not gotten it to work. When I run mex -v ndfun.c this is the output I get.
>> mex -v ndfun.c
**************************************************************************
Warning: Neither -compatibleArrayDims nor -largeArrayDims is selected.
Using -compatibleArrayDims. In the future, MATLAB will require
the use of -largeArrayDims and remove the -compatibleArrayDims
option. For more information, see:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html
**************************************************************************
-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
FILE = /Users/artinsarraf/.matlab/R2013a/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /Applications/MATLAB_R2013a.app
-> CC = xcrun -sdk macosx10.9 clang
-> CC flags:
CFLAGS = -fno-common -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -fexceptions
CDEBUGFLAGS = -g
COPTIMFLAGS = -O2 -DNDEBUG
CLIBS = -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx -lmex -lmat -lstdc++
arguments = -DMX_COMPAT_32
-> CXX = xcrun -sdk macosx10.9 clang++
-> CXX flags:
CXXFLAGS = -fno-common -fexceptions -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O2 -DNDEBUG
CXXLIBS = -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx -lmex -lmat -lstdc++
arguments = -DMX_COMPAT_32
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -m64 -fbackslash
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx -lmex -lmat -L -lgfortran -L -lgfortranbegin
arguments = -DMX_COMPAT_32
-> LD = xcrun -sdk macosx10.9 clang
-> Link flags:
LDFLAGS = -arch x86_64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2013a.app/extern/lib/maci64/mexFunction.map
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexmaci64
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------
-> xcrun -sdk macosx10.9 clang -c -I/Applications/MATLAB_R2013a.app/extern/include -I/Applications/MATLAB_R2013a.app/simulink/include -DMATLAB_MEX_FILE -fno-common -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -fexceptions -DMX_COMPAT_32 -O2 -DNDEBUG "ndfun.c"
ndfun.c:403:7: warning: implicit declaration of function 'zgemm_' is invalid in C99
[-Wimplicit-function-declaration]
BLASCALL(zgemm)("N", "N", &m, &m, &m, &cone...
^
ndfun.c:74:21: note: expanded from macro 'BLASCALL'
#define BLASCALL(f) f ## _
^
<scratch space>:207:1: note: expanded from here
zgemm_
^
ndfun.c:614:4: warning: implicit declaration of function 'dgeev_' is invalid in C99
[-Wimplicit-function-declaration]
BLASCALL(dgeev)("N", &jobvr, &m, input + i*inputstride, &m, outeigs...
^
ndfun.c:74:21: note: expanded from macro 'BLASCALL'
#define BLASCALL(f) f ## _
^
<scratch space>:207:1: note: expanded from here
dgeev_
^
2 warnings generated.
-> xcrun -sdk macosx10.9 clang -O -arch x86_64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2013a.app/extern/lib/maci64/mexFunction.map -o "ndfun.mexmaci64" ndfun.o -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx -lmex -lmat -lstdc++
Undefined symbols for architecture x86_64:
"_dgecon_", referenced from:
_compute_lu in ndfun.o
"_dgeev_", referenced from:
_mexFunction in ndfun.o
"_dgemm_", referenced from:
_mexFunction in ndfun.o
"_dgetrf_", referenced from:
_compute_lu in ndfun.o
"_dgetri_", referenced from:
_mexFunction in ndfun.o
"_dgetrs_", referenced from:
_mexFunction in ndfun.o
"_zgemm_", referenced from:
_mexFunction in ndfun.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 ' "ndfun.mexmaci64"' failed.
I have also tried using a different compiler. I downloaded gfortran, but I don't know how to get mex to use it. Thanks for any help anyone can give. I don't have any other files related to the undefined symbols so I'm assuming it's a compiler problem as opposed to a problem with the code (which does work for other people).
0 Commenti
Risposta accettata
Geoff Hayes
il 25 Set 2014
Artin - a couple of the warnings are
ndfun.c:403:7: warning: implicit declaration of function 'zgemm_'
ndfun.c:614:4: warning: implicit declaration of function 'dgeev_'
Your code, ndfun.c, has defined or is using these (BLAS and/or LAPACK) functions in some way, so where have they been declared? When you build the MEX file from
mex -v ndfun.c
you are not including any libraries to link to these functions.
Doing a web search on ndfun.c turns up http://www.mit.edu/~pwb/matlab/ndfun/ndfun.c which has the statement (in the header)
TO COMPILE: This file makes extensive use of BLAS and LAPACK functions. "New" versions of MATLAB require the explicit linking of the library that supports those functions, on both Windows and UNIX. On Linux, my command line is: "mex ndfun.c -lmwlapack". I'm not sure if Windows is the same.
So I tried (on my Mac)
mex ndfun.c -lmwlapack
and the following errors were observed
Error using mex
Undefined symbols for architecture x86_64:
"_dgemm_", referenced from:
_mexFunction in ndfun.o
"_zgemm_", referenced from:
_mexFunction in ndfun.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So it got a little further than running the same command without the library. Adding the BLAS library
mex ndfun.c -lmwlapack -lmwblas
allowed the MEX file (ndfun.mexmaci64) to be built successfully (though there were a couple of warnings).
There is a MATLAB link that describes how to call LAPACK and BLAS functions from MEX files. You may want to look at this as well.
3 Commenti
Geoff Hayes
il 25 Set 2014
Modificato: Geoff Hayes
il 25 Set 2014
I found the two libraries (libmwblas.dylib and libmwlapack.dylib) at /Applications/MATLAB_R2014a.app/bin/maci64.
As for building multiple C files, yes, both files should be in the build command. While I've never tried this, presumably you would do something like
mex myMexFunc.c other1.c other2.c -I/Users/geoff/otherIncludeFiles
where myMexFunc.c is the MEX function, other1.c and other2.c are the additional C files to build, and -I/Users/geoff/otherIncludeFiles is the directory to search for additional header files (presumably your myMexFunc.c includes the other1.h and other2.h header files). See MEX options for additional options to the MEX build command.
EDIT
The above assumes that all C files are in the same directory/folder.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Write C Functions Callable from MATLAB (MEX Files) in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!