My question is about linking errors I get when compiling with external libraries using mex. I'm trying to compile C++ code using the external library fftw3 using Matlab's mex on MacOS using clang++. Here is an example
main.cpp
#include "fftw3.h"
int main(){
double * test = (double *) fftw_malloc(10*sizeof(double));
}
compiling this works
$ clang++ main.cpp -L/usr/local/lib -lfftw3
Now I try something similar with mex
mex.cpp
#include "math.h"
#include "matrix.h"
#include "mex.h"
#include "fftw3.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double * test = (double *) fftw_malloc(10*sizeof(double));
}
in MATLAB
>> mex -setup C++;
>> mex -L/usr/local/lib -lfftw3 CXXFLAGS='-L/usr/local/lib -lfftw3' mex.cpp
Building with 'Xcode Clang++'.
Error using mex
clang: warning: -lfftw3: 'linker' input unused
clang: warning: argument unused during compilation: '-L/usr/local/lib'
/path/to/file/mex.cpp:4:10:
fatal error: 'fftw3.h' file not found
#include "fftw3.h"
^
1 error generated.
using the -v flag I get more detailed errors
Verbose mode is on.
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:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
... Looking for compiler 'Xcode Clang++' ...
... Looking for environment variable 'DEVELOPER_DIR' ...No.
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer' ...Yes.
... Executing command 'which xcrun' ...Yes ('/usr/bin/xcrun').
... Looking for folder '/usr/bin' ...Yes.
... Executing command 'defaults read com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...No.
... Executing command 'defaults read /Library/Preferences/com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...Yes ('7.1.1').
... Executing command '
agreed=7.1.1
if echo $agreed | grep -E '[\.\"]' >/dev/null; then
lhs=`expr "$agreed" : '\([0-9]*\)[\.].*'`
rhs=`expr "$agreed" : '[0-9]*[\.]\(.*\)$'`
if echo $rhs | grep -E '[\."]' >/dev/null; then
rhs=`expr "$rhs" : '\([0-9]*\)[\.].*'`
fi
if [ $lhs -gt 4 ] || ( [ $lhs -eq 4 ] && [ $rhs -ge 3 ] ); then
echo $agreed
else
exit 1
fi
fi' ...Yes ('7.1.1').
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk' ...Yes.
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk' ...Yes.
... Executing command 'echo /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk | rev | cut -c1-10 | rev | egrep -oh '[0-9]+\.[0-9]+'' ...Yes ('10.11').
Found installed compiler 'Xcode Clang++'.
Options file details
-------------------------------------------------------------------
Compiler location: /Applications/Xcode.app/Contents/Developer
Options file: ~/.matlab/R2014b/mex_C++_maci64.xml
CMDLINE100 : /usr/bin/xcrun -sdk macosx10.11 clang++ -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2014b.app/extern/include" -I"/Applications/MATLAB_R2014b.app/simulink/include" -L/usr/local/lib -lfftw3 -O2 -DNDEBUG /path/to/file/mex.cpp -o /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.o
CMDLINE200 : /usr/bin/xcrun -sdk macosx10.11 clang++ -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.11 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -framework Cocoa -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014b.app/extern/lib/maci64/mexFunction.map" -O -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014b.app/extern/lib/maci64/mexFunction.map" /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.o -lfftw3 -L/usr/local/lib -L"/Applications/MATLAB_R2014b.app/bin/maci64" -lmx -lmex -lmat -o mex.mexmaci64
CMDLINE300 : rm -f /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.o
CXX : /usr/bin/xcrun -sdk macosx10.11 clang++
DEFINES : -DMX_COMPAT_32 -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CXXFLAGS : -L/usr/local/lib -lfftw3
INCLUDE : -I"/Applications/MATLAB_R2014b.app/extern/include" -I"/Applications/MATLAB_R2014b.app/simulink/include"
CXXOPTIMFLAGS : -O2 -DNDEBUG
CXXDEBUGFLAGS : -g
LDXX : /usr/bin/xcrun -sdk macosx10.11 clang++
LDFLAGS : -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.11 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -framework Cocoa -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014b.app/extern/lib/maci64/mexFunction.map"
LDBUNDLE : -bundle
LINKEXPORT : -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014b.app/extern/lib/maci64/mexFunction.map"
LINKLIBS : -lfftw3 -L/usr/local/lib -L"/Applications/MATLAB_R2014b.app/bin/maci64" -lmx -lmex -lmat
LDOPTIMFLAGS : -O
LDDEBUGFLAGS : -g
OBJEXT : .o
LDEXT : .mexmaci64
DEVELOPER_DIR_CHECK :
XCODE_DIR : /Applications/Xcode.app/Contents/Developer
XCRUN_DIR : /usr/bin
XCODE_AGREED_VERSION : 7.1.1
ISYSROOT : /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
SDKVER : 10.11
MATLABROOT : /Applications/MATLAB_R2014b.app
ARCH : maci64
SRC : /path/to/file/mex.cpp
OBJ : /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.o
OBJS : /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.o
SRCROOT : /path/to/file/mex
DEF : /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.def
EXP : mex.exp
LIB : mex.lib
EXE : mex.mexmaci64
ILK : mex.ilk
MANIFEST : mex.mexmaci64.manifest
TEMPNAME : mex
EXEDIR :
EXENAME : mex
OPTIM : -O2 -DNDEBUG
LINKOPTIM : -O
-------------------------------------------------------------------
Building with 'Xcode Clang++'.
/usr/bin/xcrun -sdk macosx10.11 clang++ -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2014b.app/extern/include" -I"/Applications/MATLAB_R2014b.app/simulink/include" -L/usr/local/lib -lfftw3 -O2 -DNDEBUG /path/to/file/mex.cpp -o /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.o
Error using mex
clang: warning: -lfftw3: 'linker' input unused
clang: warning: argument unused during compilation: '-L/usr/local/lib'
/path/to/file/mex.cpp:4:10:
fatal error: 'fftw3.h' file not found
#include "fftw3.h"
^
1 error generated.
The warnings
clang: warning: -lfftw3: 'linker' input unused
clang: warning: argument unused during compilation: '-L/usr/local/lib'
are there because you are setting CXXFLAGS to contain these flags. This variable is for compiler flags, but -L and -l are linker flags. Simply remove the CXXFLAGS definition from your mex command.
The error
/path/to/file/mex.cpp:4:10:
fatal error: 'fftw3.h' file not found
#include "fftw3.h"
^
1 error generated.
is because the compiler cannot find the fftw4.h header file. You need to tell the compiler where to find it:
mex -I/usr/local/include -L/usr/local/lib -lfftw3 mex.cpp
Note that in your first case, where you call clang++ directly, it is likely that CLang is configured to look for header files in /usr/local/include, it's a standard place. But when mex invokes your compiler (I don't even know if it's the same one?) apparently this location is not added to the search path.
Related
I'm trying to use MinGW gfortran with MATLAB R2019a on Windows 10 by writing a mexopts XML file based on existing XML files. I have cygwin installed with MinGW gcc, and I've been able to run mex -setup referencing the XML file successfully. When I try to compile the timestwo.F file to test the setup (using mex -R2018a timestwo.F90), I get a bunch of errors:
Building with 'cygwin MinGW64 Compiler (Fortran)'.
C:\cygwin64\bin\x86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:\Program Files\MATLAB\R2019a\extern\include" -I"C:\Program Files\MATLAB\R2019a\simulink\include" -I"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:\cygwin64\home\user\MATLAB\timestwo.F90" -o C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o
f951: Warning: Nonexistent include directory ‘C:\Program Files\MATLAB\R2019a\simulink\include’ [-Wmissing-include-dirs]
C:\cygwin64\bin\x86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:\Program Files\MATLAB\R2019a\extern\include" -I"C:\Program Files\MATLAB\R2019a\simulink\include" -I"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:\Program Files\MATLAB\R2019a\extern\version\fortran_mexapi_version.F" -o C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\fortran_mexapi_version.o
f951: Warning: Nonexistent include directory ‘C:\Program Files\MATLAB\R2019a\simulink\include’ [-Wmissing-include-dirs]
C:\cygwin64\bin\x86_64-w64-mingw32-gfortran -pthread -shared -O3 -mtune=native -Wl,--version-script,"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64\fortran_exportsmexfileversion.map" C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\fortran_mexapi_version.o -Wl,-L"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -L"C:\cygwin64\lib\gcc\x86_64-w64-mingw32\7.4.0" -lgfortran -o timestwo.mexw64
Error using mex
C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o:timestwo.F90:(.text+0x47): undefined reference to
`mxisnumeric800_'
C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o:timestwo.F90:(.text+0x6a): undefined reference to
`mexerrmsgidandtxt800_'
C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o:timestwo.F90:(.text+0x72): undefined reference to
`mxgetdoubles800_'
C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o:timestwo.F90:(.text+0x7d): undefined reference to `mxgetm800_'
C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o:timestwo.F90:(.text+0x8c): undefined reference to `mxgetn800_'
C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o:timestwo.F90:(.text+0xa6): undefined reference to
`mxcopyptrtoreal8800_'
C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o:timestwo.F90:(.text+0xba): undefined reference to
`mxcreatedoublematrix800_'
C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o:timestwo.F90:(.text+0xc4): undefined reference to
`mxgetdoubles800_'
C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o:timestwo.F90:(.text+0xe5): undefined reference to
`mxcopyreal8toptr800_'
C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o:timestwo.F90:(.text+0x10d): undefined reference to
`mexerrmsgidandtxt800_'
C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o:timestwo.F90:(.text+0x13b): undefined reference to
`mexerrmsgidandtxt800_'
collect2: error: ld returned 1 exit status
Here's my source:
! Gateway routine
#include "fintrf.h"
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
implicit none
mwPointer plhs(*), prhs(*)
integer nlhs, nrhs
! Declarations
mwPointer mxGetDoubles
mwPointer mxCreateDoubleMatrix
integer mxIsNumeric
mwPointer mxGetM, mxGetN
mwPointer x_ptr, y_ptr
mwPointer mrows, ncols
mwSize size
! Declare variables for computational routine
real*8 x_input, y_output
! Make sure input is valid
if(nrhs /= 1) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:nInput', &
'One input required.')
elseif(nlhs > 1) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:nOutput', &
'Too many output arguments.')
endif
if(mxIsNumeric(prhs(1)) == 0) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:NonNumeric', &
'Input must be a number.')
endif
! Read input array
x_ptr = mxGetDoubles(prhs(1))
! Get size of array
mrows = mxGetM(prhs(1))
ncols = mxGetN(prhs(1))
size = mrows*ncols
! Create a Fortran array from the input
call mxCopyPtrToReal8(x_ptr,x_input,size)
! Prepare a matrix for output
plhs(1) = mxCreateDoubleMatrix(mrows,ncols,0)
y_ptr = mxGetDoubles(plhs(1))
call timestwo(y_output, x_input)
! copy results to output argument
call mxCopyReal8ToPtr(y_output,y_ptr,size)
return
end
subroutine timestwo(y_output, x_input)
real*8 x_input, y_output
y_output = 2.0*x_input
return
end
The output is the same if I try with the included matlabroot\extern\examples\refbook\timestwo.F fixed-form version.
My options file details (first part of output from mex -v -R2018a timestwo.F90)
Compiler location: C:\cygwin64
Options file: C:\Users\user\AppData\Roaming\MathWorks\MATLAB\R2019a\mex_FORTRAN_win64.xml
CMDLINE2 : C:\cygwin64\bin\x86_64-w64-mingw32-gfortran -pthread -shared -O3 -mtune=native -Wl,--version-script,"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64\fortran_exportsmexfileversion.map" C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\fortran_mexapi_version.o -Wl,-L"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -L"C:\cygwin64\lib\gcc\x86_64-w64-mingw32\7.4.0" -lgfortran -o timestwo.mexw64
FC : C:\cygwin64\bin\x86_64-w64-mingw32-gfortran
DEFINES : -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD
FFLAGS : -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
INCLUDE : -I"C:\Program Files\MATLAB\R2019a\extern\include" -I"C:\Program Files\MATLAB\R2019a\simulink\include" -I"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64"
FOPTIMFLAGS : -O3 -mtune=native
FDEBUGFLAGS : -g -Wall
LDF : C:\cygwin64\bin\x86_64-w64-mingw32-gfortran
LDFLAGS : -pthread
LDTYPE : -shared
LINKEXPORT : -Wl,--version-script,"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64\fexport.map"
LINKEXPORTVER : -Wl,--version-script,"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64\fortran_exportsmexfileversion.map"
LINKLIBS : -Wl,-L"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -L"C:\cygwin64\lib\gcc\x86_64-w64-mingw32\7.4.0" -lgfortran
LDOPTIMFLAGS : -O3 -mtune=native
LDDEBUGFLAGS : -g -Wall
OBJEXT : .o
LDEXT : .mexw64
SETENV : set COMPILER=C:\cygwin64\bin\x86_64-w64-mingw32-gfortran
set COMPFLAGS=-fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD
set OPTIMFLAGS=-O3 -mtune=native
set DEBUGFLAGS=-g -Wall
set LINKER=C:\cygwin64\bin\x86_64-w64-mingw32-gfortran
set LINKFLAGS=-pthread
set LINKDEBUGFLAGS=-pthread -shared -Wl,-L"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -L"C:\cygwin64\lib\gcc\x86_64-w64-mingw32\7.4.0" -lgfortran -Wl,--version-script,"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64\fexport.map"
set LDDEBUGFLAGS=-g -Wall
set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%%"
CYGWINROOT : C:\cygwin64
MATLABROOT : C:\Program Files\MATLAB\R2019a
ARCH : win64
SRC : "C:\cygwin64\home\user\MATLAB\timestwo.F90";"C:\Program Files\MATLAB\R2019a\extern\version\fortran_mexapi_version.F"
OBJ : C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o;C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\fortran_mexapi_version.o
OBJS : C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\fortran_mexapi_version.o
SRCROOT : C:\cygwin64\home\user\MATLAB\timestwo
DEF : C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.def
EXP : "timestwo.exp"
LIB : "timestwo.lib"
EXE : timestwo.mexw64
ILK : "timestwo.ilk"
MANIFEST : "timestwo.mexw64.manifest"
TEMPNAME : timestwo
EXEDIR :
EXENAME : timestwo
OPTIM : -O3 -mtune=native
LINKOPTIM : -O3 -mtune=native
CMDLINE1_0 : C:\cygwin64\bin\x86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:\Program Files\MATLAB\R2019a\extern\include" -I"C:\Program Files\MATLAB\R2019a\simulink\include" -I"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:\cygwin64\home\user\MATLAB\timestwo.F90" -o C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\timestwo.o
CMDLINE1_1 : C:\cygwin64\bin\x86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:\Program Files\MATLAB\R2019a\extern\include" -I"C:\Program Files\MATLAB\R2019a\simulink\include" -I"C:\Program Files\MATLAB\R2019a\extern\lib\win64\mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:\Program Files\MATLAB\R2019a\extern\version\fortran_mexapi_version.F" -o C:\Users\user\AppData\Local\Temp\mex_62691295256641_4248\fortran_mexapi_version.o
It seems like the mex-specific types like mwPointer defined in fintrf.h aren't being defined, even though I've included its location. Why are these types not recognized?
Summary
I am trying to write some MEX files that use LAPACK, and I thought I'd start by looking through the examples provided by MathWorks.
However, I am having some trouble compiling them. After copying the matrixDivide.c example from [MATLAB root]/extern/examples/refbook into a working directory, I tried to build a mex file, but it failed with error undefined reference to `dgesv_' (where dgesv is the name of the LAPACK routine being called).
I was able to build a different mex example (timestwo.c) that doesn't use LAPACK.
So what's going on? What's the deal with the trailing underscore? What about this memcpy warning?
More info
I think this is fairly similar to the issues encountered by this user:
How can I use CLAPACK,BLAS or LAPACK in a mex file?
I've tried this with MATLAB R2013b and R2014b. I am running on 64-bit Linux (RHEL 6) and my compiler is gcc 4.4.7 (which is not the MathWorks recommended version, but is the newest version I can get).
Here are the relevant portions of the code I'm trying to compile:
1 /*=========================================================
2 * matrixDivide.c - Example for illustrating how to use
3 * LAPACK within a C MEX-file.
4 *
5 * X = matrixDivide(A,B) computes the solution to a
6 * system of linear equations A * X = B
7 * using LAPACK routine DGESV, where
8 * A is an N-by-N matrix
9 * X and B are N-by-1 matrices.
10 *
11 * This is a MEX-file for MATLAB.
12 * Copyright 2009-2010 The MathWorks, Inc.
13 *=======================================================*/
14 /* $Revision: 1.1.6.3 $ $Date: 2011/01/28 18:11:56 $ */
15
16 #if !defined(_WIN32)
17 #define dgesv dgesv_
18 #endif
19
20 #include "mex.h"
21 #include "lapack.h"
22
23 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
24 {
[ snip ]
73 /* Call LAPACK */
74 dgesv(&m,&n,A2,&m,iPivot,B2,&p,&info);
75 /* plhs[0] now holds X */
76
77 mxDestroyArray(Awork);
78 mxDestroyArray(mxPivot);
79 }
Here is the output of the failed mex build:
>> mex -v -largeArrayDims matrixDivide.c
-> mexopts.sh sourced from directory (DIR = $MATLAB/bin)
FILE = /sw/matlab/R2013b/bin/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /sw/matlab/R2013b
-> CC = gcc
-> CC flags:
CFLAGS = -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread
CDEBUGFLAGS = -g
COPTIMFLAGS = -O -DNDEBUG
CLIBS = -Wl,-rpath-link,/sw/matlab/R2013b/bin/glnxa64 -L/sw/matlab/R2013b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
arguments =
-> CXX = g++
-> CXX flags:
CXXFLAGS = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O -DNDEBUG
CXXLIBS = -Wl,-rpath-link,/sw/matlab/R2013b/bin/glnxa64 -L/sw/matlab/R2013b/bin/glnxa64 -lmx -lmex -lmat -lm
arguments =
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -Wl,-rpath-link,/sw/matlab/R2013b/bin/glnxa64 -L/sw/matlab/R2013b/bin/glnxa64 -lmx -lmex -lmat -lm
arguments =
-> LD = gcc
-> Link flags:
LDFLAGS = -pthread -shared -Wl,--version-script,/sw/matlab/R2013b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexa64
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------
-> gcc -c -I/sw/matlab/R2013b/extern/include -I/sw/matlab/R2013b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread -O -DNDEBUG "matrixDivide.c"
In file included from matrixDivide.c:21:
/sw/matlab/R2013b/extern/include/lapack.h:6907:1: warning: "dgesv" redefined
matrixDivide.c:17:1: warning: this is the location of the previous definition
matrixDivide.c: In function `mexFunction':
matrixDivide.c:64: warning: incompatible implicit declaration of built-in function ?memcpy?
-> gcc -O -pthread -shared -Wl,--version-script,/sw/matlab/R2013b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -o "matrixDivide.mexa64" matrixDivide.o -Wl,-rpath-link,/sw/matlab/R2013b/bin/glnxa64 -L/sw/matlab/R2013b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
matrixDivide.o: In function `mexFunction':
matrixDivide.c:(.text+0x1c6): undefined reference to `dgesv_'
collect2: ld returned 1 exit status
mex: link of ' "matrixDivide.mexa64"' failed.
After some more messing around, I figured out my (rather elementary) mistake.
You need to specify the -lmwlapack option (and/or -lmwblas, as appropriate) to the linker:
mex -largeArrayDims -lmwlapack matrixDivide.c
It even says so on the MathWorks page I was trying to follow along on. RTFM!
i tried to build the mod_tile as in the link
then i was getting the same error
and tried came got the fix from this forum
i exported these
export CXXFLAGS="$(mapnik-config --cflags)"
export LDFLAGS="$(mapnik-config --ldflags)"
adding #include at the top of src/gen_tile.cpp
and changed the Makefile with --std=gnu++11
and i'm new to the linux and the cpp
Making all in iniparser3.0b
make[1]: Entering directory `/root/src/mod_tile/iniparser3.0b'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/root/src/mod_tile/iniparser3.0b'
make[1]: Entering directory `/root/src/mod_tile'
depbase=`echo src/gen_tile.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
g++ -DHAVE_CONFIG_H -I. -I./includes -I/usr/include/freetype2 -I/usr/local/include -I/usr/local/include/mapnik/agg -I/opt/PostgreSQL/9.3/include -I/usr/include -I/usr/include/freetype2 -I/usr/include/libxml2 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/libpng12 -I/usr/include -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libdrm -I/usr/include/libpng12 -DSYSTEM_LIBINIPARSER=0 -I/usr/local/include -I/usr/local/include/mapnik/agg -I/opt/PostgreSQL/9.3/include -I/usr/include -I/usr/include/freetype2 -I/usr/include/libxml2 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/libpng12 -DSHAPE_MEMORY_MAPPED_FILE -DBIGINT -DBOOST_REGEX_HAS_ICU -DHAVE_JPEG -DMAPNIK_USE_PROJ4 -DHAVE_PNG -DHAVE_TIFF -DLINUX -DMAPNIK_THREADSAFE -DBOOST_SPIRIT_NO_PREDEFINED_TERMINALS=1 -DBOOST_PHOENIX_NO_PREDEFINED_TERMINALS=1 -DBOOST_SPIRIT_USE_PHOENIX_V3=1 -DNDEBUG -DHAVE_CAIRO -DGRID_RENDERER -DHAVE_LIBXML2 -std=c++11 -Wall -Wsign-compare -pthread -ftemplate-depth-300 -Wno-pragmas -O3 -MT src/gen_tile.o -MD -MP -MF $depbase.Tpo -c -o src/gen_tile.o src/gen_tile.cpp &&\
mv -f $depbase.Tpo $depbase.Po
src/gen_tile.cpp: In function ‘void parameterize_map_max_connections(mapnik::Map&, int)’:
src/gen_tile.cpp:180:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < m.layer_count(); i++) {
^
src/gen_tile.cpp:181:22: error: ‘class mapnik::Map’ has no member named ‘getLayer’
layer& l = m.getLayer(i);
^
src/gen_tile.cpp:182:43: error: invalid use of incomplete type ‘class mapnik::datasource’
parameters params = l.datasource()->params();
^
In file included from src/gen_tile.cpp:1:0:
/usr/local/include/mapnik/layer.hpp:37:7: error: forward declaration of ‘class mapnik::datasource’
class datasource;
^
src/gen_tile.cpp:188:9: error: ‘shared_ptr’ is not a member of ‘boost’
boost::shared_ptr<datasource> ds = datasource_cache::instance().create(params);
^
src/gen_tile.cpp:188:9: note: suggested alternative:
In file included from /usr/include/c++/4.8/bits/shared_ptr.h:52:0,
from /usr/include/c++/4.8/memory:82,
from /usr/local/include/mapnik/layer.hpp:32,
from src/gen_tile.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr_base.h:261:11: note: ‘std::shared_ptr’
class shared_ptr;
^
src/gen_tile.cpp:188:37: error: expected primary-expression before ‘>’ token
boost::shared_ptr<datasource> ds = datasource_cache::instance().create(params);
^
src/gen_tile.cpp:188:39: error: ‘ds’ was not declared in this scope
boost::shared_ptr<datasource> ds = datasource_cache::instance().create(params);
^
src/gen_tile.cpp: In function ‘protoCmd render(xmlmapconfig*, int, int, int, char*, metaTile&)’:
src/gen_tile.cpp:259:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (yy = 0; yy < render_size_ty; yy++) {
^
src/gen_tile.cpp:260:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (xx = 0; xx < render_size_tx; xx++) {
^
make[1]: *** [src/gen_tile.o] Error 1
make[1]: Leaving directory `/root/src/mod_tile'
make: *** [all-recursive] Error 1
Please let me know anything i did wrong in the flow?
i am using this code
https://github.com/springmeyer/mod_tile
to build mod_tile now its working fine.
I'm unable to build Doxygen on x86_64-linux.
I have Doxygen-1.8.6 unpacked.
I have libiconv-1.14 unpacked, built, installed.
I keep getting:
g++ -c -pipe -fsigned-char -D_LARGEFILE_SOURCE -Wall -W -O2 -I../qtools -I../libmd5 -I. -o ../objects/main.o main.cpp
g++ -o ../bin/doxygen ../objects/main.o -L../lib -ldoxygen -ldoxycfg -lqtools -lmd5 -lpthread
../lib/libdoxycfg.a(portable_c.o): In function `portable_iconv_close':
portable_c.c:(.text+0x1): undefined reference to `libiconv_close'
../lib/libdoxycfg.a(portable_c.o): In function `portable_iconv':
portable_c.c:(.text+0x11): undefined reference to `libiconv'
../lib/libdoxycfg.a(portable_c.o): In function `portable_iconv_open':
portable_c.c:(.text+0x21): undefined reference to `libiconv_open'
collect2: ld returned 1 exit status
Which iconv gives:
/usr/local/bin/iconv
as expected.
Any ideas?
add -liconv to the end of the line in src/doxygen.pro.in:
unix:LIBS += -L../lib -ldoxygen -lvhdlparser -ldoxycfg -lqtools -lmd5 -lpthread %%SQLITE3_LIBS%% %%LIBCLANG_LIBS%% -liconv
Up until recently I've been able to compile mex functions fine on my mac osx 10.8.4
but now it gives me the error as follows (for convenience I have included the entire -v invocation):
**************************************************************************
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 = .)
FILE = /Users/munanxu/Dropbox/Code/CUDA/mexThomasTDM/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /Applications/MATLAB_R2013a.app
-> CC = xcrun -sdk macosx10.7 clang
-> CC flags:
CFLAGS = -fno-common -arch x86_64 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOS
X10.7.sdk -mmacosx-version-min=10.7 -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.7 clang++
-> CXX flags:
CXXFLAGS = -fno-common -fexceptions -arch x86_64 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX
10.7.sdk -mmacosx-version-min=10.7
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.7 clang
-> Link flags:
LDFLAGS = -arch x86_64 -Wl,-
syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/
SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7 -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.7 clang -g -arch x86_64 -Wl,-
syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/
SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7 -bundle -Wl,-
exported_symbols_list,/Applications/MATLAB_R2013a.app/extern/lib/maci64/mexFunction.map -o
"inputsTest.mexmaci64" "inputsTest.o" -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx
-lmex -lmat -lstdc++
Undefined symbols for architecture x86_64:
"_mexFunction", referenced from:
-exported_symbol[s_list] command line option
ld: symbol(s) not found for architecture x86_64
I had copied the original mexopts.sh file to the local directory to ensure that the mex compiler was using the correct version. I had also previously compiled my cpp file using g++ just to make sure the code was compiled natively for the x86_64 architecture. However, the same result occurs when I attempt to use the mex compiler to do compilation and linking.
Any ideas on what might be going on here? It seems that people have had this issue before, but mostly with missing libraries or definitions. I have definitely defined a mexFunction in my source file.
I think Amro is correct, I would put this as a comment, but it's a bit large, I find this for clang command line options to select target CPU
Registered Targets:
alpha - Alpha [experimental]
arm - ARM
bfin - Analog Devices Blackfin [experimental]
c - C backend ... ...
mblaze - MBlaze
mips - Mips ...
msp430 - MSP430 [experimental] ...
thumb - Thumb
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
xcore - XCoreI'm thinking Amro is correct:
So is -arch x86-64 the right command line switch, rather than x86_64