我想使用Matlab 2012a使用OSX 10.9来获取文件。我用于mex文件的命令如下:
mex -v -L/usr/include/ -I/usr/include/ -I/usr/local/Cellar/hdf5/1.8.12/include/ -larmadillo -lgfortran armaMex_demo.cpp
文件armaMex_demp.cpp
取决于位于/usr/include/armadillo
的库armadillo。以下是我理解用于编译文件的命令:
-v
表示详细-L/usr/include/
告诉链接器在/usr/include/
-I/usr/include/
告诉编译器在/usr/include/
-I/usr/local/Cellar/hdf5/1.8.12/include/
与上述相同-larmadillo
告诉班轮使用名为armadillo
不幸的是我无法编译该文件。这是我得到的输出
-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
FILE = /Users/Ivan/.matlab/R2012a/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /Applications/MATLAB_R2012a.app
-> CC = llvm-gcc
-> CC flags:
CFLAGS = -fno-common -no-cpp-precomp -Dchar16_t=uint16_T -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_R2012a.app/bin/maci64 -lmx -lmex -lmat -lstdc++
arguments = -DMX_COMPAT_32
-> CXX = llvm-g++
-> CXX flags:
CXXFLAGS = -fno-common -no-cpp-precomp -fexceptions -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/ -mmacosx-version-min=10.9 -std=c++11
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O2 -DNDEBUG
CXXLIBS = -L/Applications/MATLAB_R2012a.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_R2012a.app/bin/maci64 -lmx -lmex -lmat -L -lgfortran -L -lgfortranbegin
arguments = -DMX_COMPAT_32
-> LD = llvm-gcc
-> Link flags:
LDFLAGS = -Wl,-twolevel_namespace -undefined error -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_R2012a.app/extern/lib/maci64/mexFunction.map
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexmaci64
arguments = -L/usr/include/ -larmadillo -lgfortran
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments = -L/usr/include/ -larmadillo -lgfortran
----------------------------------------------------------------
-> llvm-g++ -c -I/usr/include/ -I/usr/local/Cellar/hdf5/1.8.12/include/ -I/Applications/MATLAB_R2012a.app/extern/include -I/Applications/MATLAB_R2012a.app/simulink/include -DMATLAB_MEX_FILE -fno-common -no-cpp-precomp -fexceptions -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/ -mmacosx-version-min=10.9 -std=c++11 -DMX_COMPAT_32 -O2 -DNDEBUG "armaMex_demo.cpp"
-> llvm-gcc -O -Wl,-twolevel_namespace -undefined error -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_R2012a.app/extern/lib/maci64/mexFunction.map -o "armaMex_demo.mexmaci64" armaMex_demo.o -L/usr/include/ -larmadillo -lgfortran -L/Applications/MATLAB_R2012a.app/bin/maci64 -lmx -lmex -lmat -lstdc++
ld:找不到-larmadillo的库 clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)
mex: link of ' "armaMex_demo.mexmaci64"' failed.
使用mex时出错(第206行) 无法成功完成。
run_demo出错(第3行) mex -v -L / usr / include / -I / usr / include / -I / usr / local / Cellar / hdf5 / 1.8.12 / include / -larmadillo -lgfortran armaMex_demo.cpp
有人可以解释我收到错误的原因吗?
修改1:
以下
mex -v -I/usr/include/ -I/usr/local/Cellar/hdf5/1.8.12/include/ armaMex_demo.cpp
的工作。有人可以解释为什么第一次失败但第二次没有?我只是通过反复试验才发现它。