I am rewriting some of my matlab code using mex and C++ to make it read large files in faster. I am trying to compile the code and get this error. I am new to mex and would appreciate some help in discovering why the code won't compile. Thanks in advance.
>> mex -v read_svm.cpp
**************************************************************************
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/anb/.matlab/R2013a/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/MacOSX10.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/MacOSX10.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++ -c -I/Applications/MATLAB_R2013a.app/extern/include -I/Applications/MATLAB_R2013a.app/simulink/include -DMATLAB_MEX_FILE -fno-common -fexceptions -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7 -DMX_COMPAT_32 -O2 -DNDEBUG "read_svm.cpp"
-> xcrun -sdk macosx10.7 clang -O -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 "read_svm.mexmaci64" read_svm.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
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mex: link of ' "read_svm.mexmaci64"' failed.
Error using mex (line 206)
Unable to complete successfully.
Do you have a void mexFunction(int nout, mxArray* pout[], int nin, const mxArray* pin[]))
defined in read_svm.cpp file?
Matlab expects your mex file to have a function with that signiture in your code. This is the function it then calls when you execute the mex file.
Related
I am currently trying to compile a small program I have been working on with Clang and am getting the following error on compilation using scons as the build system:
/usr/bin/clang++ -o src/PluGen/main.o -c -std=c++17 -fPIC -I. -O2 -fno-strict-aliasing -fpermissive -fopenmp --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -fpermissive -fPIC -I. -O2 -flto -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -DHAVE_PYTHON -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DLARGE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_PERL -DREENTRANT -DHAVE_R -I/usr/include -I/usr/local/include -Isrc -I/usr/include/python3.10 -I/usr/lib/perl5/5.36/core_perl/CORE -I/usr/include/R -I/usr/lib/R/library/Rcpp/include -I/usr/lib/R/library/RInside/include -I/usr/lib/R/site-library/RInside/include -I/usr/lib/R/site-library/Rcpp/include -I/usr/local/lib/R/library/Rcpp/include -I/usr/local/lib/R/library/RInside/include -I/usr/local/lib/R/site-library/RInside/include -I/usr/local/lib/R/site-library/Rcpp/include -I/usr/local/lib/R/site-library/RInside/lib src/PluGen/main.cxx
...
/usr/bin/clang++ -o PluGen/plugen -rdynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.36/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now src/PluGen/main.o src/PluGen/PluginGenerator.o -L/lib -L/usr/lib -L/usr/local/lib -L/usr/lib/perl5/5.36/core_perl/CORE -L/usr/lib/R/lib -L/usr/lib/R/library/RInside/lib -L/usr/lib/R/site-library/RInside/lib -L/usr/local/lib/R/library/RInside/lib -L/usr/local/lib/R/site-library/RInside/lib -Llib -lc -lc++ -lstdc++fs
src/PluGen/main.o: file not recognized: file format not recognized
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
main.o is being generated as a IR bitcode
file src/PluGen/main.o
src/PluGen/main.o: LLVM IR bitcode
Running the linker outside of the scons builder yields the following message:
clang version 14.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/12.1.0
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0
Candidate multilib: .;#m64
Candidate multilib: 32;#m32
Selected multilib: .;#m64
"/usr/bin/ld" -pie -export-dynamic --eh-frame-hdr -m elf_x86_64 -export-dynamic -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o PluGen/plugen /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../lib64/Scrt1.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../lib64/crti.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/crtbeginS.o -L/lib -L/usr/lib -L/usr/local/lib -L/usr/lib/perl5/5.36/core_perl/CORE -L/usr/lib/R/lib -L/usr/lib/R/library/RInside/lib -L/usr/lib/R/site-library/RInside/lib -L/usr/local/lib/R/library/RInside/lib -L/usr/local/lib/R/site-library/RInside/lib -Llib -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0 -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib -L/lib -L/usr/lib -E -rpath /usr/lib/perl5/5.36/core_perl/CORE -O1 --sort-common --as-needed -z relro -z now src/PluGen/main.o src/PluGen/PluginGenerator.o -lc -lc++ -lstdc++fs -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/crtendS.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../lib64/crtn.o
src/PluGen/main.o: file not recognized: file format not recognized
The program does compile correctly using GCC. Just not with Clang.
What is going on?
You are using -flto when compiling, but not when linking. clang can't do that. -c -flto compiles to LLVM IR bitcodes which the linker cannot use directly. You should either drop -flto everywhere, or use it everywhere.
$ clang++ -flto -c hello.cpp
$ file hello.o
hello.o: LLVM IR bitcode
$ clang++ -o hello hello.o && echo Ok
hello.o: file not recognized: file format not recognized
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$ clang++ -o hello hello.o -flto && echo Ok
Ok
gcc works differently. It compiles to "fat objects" with both machine code and internal compiler representation baked in. Linker can use these, and apply the LTO plugin automatically.
$ g++ -c hello.cpp -flto
$ file hello.o
hello.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
$ g++ -o hello hello.o && echo Ok
Ok
I'm trying to evaluate edge detection results using HED's code in matlab2020a(macOsx10.14) and get these error:
MEX file
'/Users/test/EdgeDetection/eval/edges/private2/correspondPixels.mexmaci64'
invalid:
dlopen(/Users/test/EdgeDetection/eval/edges/private2/correspondPixels.mexmaci64,
6): Library not loaded: #loader_path/libmex.dylib
Referenced from:
/Users/test/EdgeDetection/eval/edges/private2/correspondPixels.mexmaci64
Reason: image not found
So I try to compile the correspondPixels.cc file using
mex -v correspondPixels.cc
the output like this:
INCLUDE = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1;/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/10.0.0/include;/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks;/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1;/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/10.0.0/include;/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks;
Options file details
-------------------------------------------------------------------
Compiler location: /Applications/Xcode.app/Contents/Developer
Options file: /Users/a710/Library/Application Support/MathWorks/MATLAB/R2020a/mex_C++_maci64.xml
CMDLINE200 : /usr/bin/xcrun -sdk macosx10.14 clang++ -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.9 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -framework Cocoa -bundle -stdlib=libc++ -O -Wl,-exported_symbols_list,"/Applications/Polyspace/R2020a/extern/lib/maci64/mexFunction.map" -Wl,-exported_symbols_list,"/Applications/Polyspace/R2020a/extern/lib/maci64/c_exportsmexfileversion.map" -Wl,-U,_mexCreateMexFunction -Wl,-U,_mexDestroyMexFunction -Wl,-U,_mexFunctionAdapter -Wl,-exported_symbols_list,"/Applications/Polyspace/R2020a/extern/lib/maci64/cppMexFunction.map" /var/folders/8q/gj54rs5s6cv3whdzmhkf79_m0000gn/T/mex_1719808412277515_56763/correspondPixels.o /var/folders/8q/gj54rs5s6cv3whdzmhkf79_m0000gn/T/mex_1719808412277515_56763/cpp_mexapi_version.o -L"/Applications/Polyspace/R2020a/bin/maci64" -lmx -lmex -lmat -L"/Applications/Polyspace/R2020a/extern/bin/maci64" -lMatlabDataArray -lMatlabEngine -o correspondPixels.mexmaci64
CC : /usr/bin/xcrun -sdk macosx10.14 clang
CXX : /usr/bin/xcrun -sdk macosx10.14 clang++
DEFINES : -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
MACOSX_DEPLOYMENT_TARGET : 10.9
CFLAGS : -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
CXXFLAGS : -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -fobjc-arc -std=c++11 -stdlib=libc++
INCLUDE : -I"/Applications/Polyspace/R2020a/extern/include" -I"/Applications/Polyspace/R2020a/simulink/include"
CXXOPTIMFLAGS : -O2 -fwrapv -DNDEBUG
CXXDEBUGFLAGS : -g
LD : /usr/bin/xcrun -sdk macosx10.14 clang
LDXX : /usr/bin/xcrun -sdk macosx10.14 clang++
LDFLAGS : -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.9 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -framework Cocoa -bundle -stdlib=libc++
LDBUNDLE : -bundle
LINKEXPORT : -Wl,-exported_symbols_list,"/Applications/Polyspace/R2020a/extern/lib/maci64/mexFunction.map"
LINKEXPORTVER : -Wl,-exported_symbols_list,"/Applications/Polyspace/R2020a/extern/lib/maci64/c_exportsmexfileversion.map"
LINKEXPORTCPP : -Wl,-U,_mexCreateMexFunction -Wl,-U,_mexDestroyMexFunction -Wl,-U,_mexFunctionAdapter -Wl,-exported_symbols_list,"/Applications/Polyspace/R2020a/extern/lib/maci64/cppMexFunction.map"
LINKLIBS : -L"/Applications/Polyspace/R2020a/bin/maci64" -lmx -lmex -lmat -L"/Applications/Polyspace/R2020a/extern/bin/maci64" -lMatlabDataArray -lMatlabEngine
LDOPTIMFLAGS : -O
LDDEBUGFLAGS : -g
OBJEXT : .o
LDEXT : .mexmaci64
SETENV : CC="/usr/bin/xcrun -sdk macosx10.14 clang"
CXX="/usr/bin/xcrun -sdk macosx10.14 clang++"
CFLAGS="-fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE "
CXXFLAGS="-fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -fobjc-arc -std=c++11 -stdlib=libc++ -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE "
COPTIMFLAGS="-O2 -fwrapv -DNDEBUG"
CXXOPTIMFLAGS="-O2 -fwrapv -DNDEBUG"
CDEBUGFLAGS="-g"
CXXDEBUGFLAGS="-g"
LD="/usr/bin/xcrun -sdk macosx10.14 clang"
LDXX="/usr/bin/xcrun -sdk macosx10.14 clang++"
LDFLAGS="-Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.9 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -framework Cocoa -bundle -stdlib=libc++ -L"/Applications/Polyspace/R2020a/bin/maci64" -lmx -lmex -lmat -L"/Applications/Polyspace/R2020a/extern/bin/maci64" -lMatlabDataArray -lMatlabEngine -Wl,-exported_symbols_list,"/Applications/Polyspace/R2020a/extern/lib/maci64/mexFunction.map""
LDDEBUGFLAGS="-g"
DEVELOPER_DIR_CHECK :
XCODE_DIR : /Applications/Xcode.app/Contents/Developer
XCRUN_DIR : /usr/bin
XCODE_AGREED_VERSION : 9.2
ISYSROOT : /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
SDKVER : 10.14
CLANG_VERSION : 10.0.0
MATLABROOT : /Applications/Polyspace/R2020a
ARCH : maci64
SRC : "/Users/hed/data/BSDS500/bench/source/correspondPixels.cc";"/Applications/Polyspace/R2020a/extern/version/cpp_mexapi_version.cpp"
OBJ : /var/folders/8q/gj54rs5s6cv3whdzmhkf79_m0000gn/T/mex_1719808412277515_56763/correspondPixels.o;/var/folders/8q/gj54rs5s6cv3whdzmhkf79_m0000gn/T/mex_1719808412277515_56763/cpp_mexapi_version.o
OBJS : /var/folders/8q/gj54rs5s6cv3whdzmhkf79_m0000gn/T/mex_1719808412277515_56763/correspondPixels.o /var/folders/8q/gj54rs5s6cv3whdzmhkf79_m0000gn/T/mex_1719808412277515_56763/cpp_mexapi_version.o
SRCROOT : /Users/hed/data/BSDS500/bench/source/correspondPixels
DEF : /var/folders/8q/gj54rs5s6cv3whdzmhkf79_m0000gn/T/mex_1719808412277515_56763/correspondPixels.def
EXP : "correspondPixels.exp"
LIB : "correspondPixels.lib"
EXE : correspondPixels.mexmaci64
ILK : "correspondPixels.ilk"
MANIFEST : "correspondPixels.mexmaci64.manifest"
TEMPNAME : correspondPixels
EXEDIR :
EXENAME : correspondPixels
OPTIM : -O2 -fwrapv -DNDEBUG
LINKOPTIM : -O
CMDLINE100_0 : /usr/bin/xcrun -sdk macosx10.14 clang++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE -I"/Applications/Polyspace/R2020a/extern/include" -I"/Applications/Polyspace/R2020a/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -fobjc-arc -std=c++11 -stdlib=libc++ -O2 -fwrapv -DNDEBUG "/Users/hed/data/BSDS500/bench/source/correspondPixels.cc" -o /var/folders/8q/gj54rs5s6cv3whdzmhkf79_m0000gn/T/mex_1719808412277515_56763/correspondPixels.o
CMDLINE100_1 : /usr/bin/xcrun -sdk macosx10.14 clang++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE -I"/Applications/Polyspace/R2020a/extern/include" -I"/Applications/Polyspace/R2020a/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -fobjc-arc -std=c++11 -stdlib=libc++ -O2 -fwrapv -DNDEBUG "/Applications/Polyspace/R2020a/extern/version/cpp_mexapi_version.cpp" -o /var/folders/8q/gj54rs5s6cv3whdzmhkf79_m0000gn/T/mex_1719808412277515_56763/cpp_mexapi_version.o
-------------------------------------------------------------------
use 'Xcode Clang++' compile.
/usr/bin/xcrun -sdk macosx10.14 clang++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE -I"/Applications/Polyspace/R2020a/extern/include" -I"/Applications/Polyspace/R2020a/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -fobjc-arc -std=c++11 -stdlib=libc++ -O2 -fwrapv -DNDEBUG "/Users/a710/Desktop/hed/data/BSDS500/bench/source/correspondPixels.cc" -o /var/folders/8q/gj54rs5s6cv3whdzmhkf79_m0000gn/T/mex_1719808412277515_56763/correspondPixels.o
In file included from /Users/a710/Desktop/hed/data/BSDS500/bench/source/correspondPixels.cc:8:
/Users/a710/Desktop/hed/data/BSDS500/bench/source/csa.hh:912:5: warning: add explicit braces to avoid dangling else [-Wdangling-else]
else
^
/Users/a710/Desktop/hed/data/BSDS500/bench/source/csa.hh:1217:25: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
(void) fprintf(stderr,nomem_msg);
^~~~~~~~~
/Users/a710/Desktop/hed/data/BSDS500/bench/source/csa.hh:1217:25: note: treat the string as an argument to avoid this
(void) fprintf(stderr,nomem_msg);
^
"%s",
/Users/a710/Desktop/hed/data/BSDS500/bench/source/csa.hh:1223:25: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
(void) fprintf(stderr,nomem_msg);
^~~~~~~~~
/Users/a710/Desktop/hed/data/BSDS500/bench/source/csa.hh:1223:25: note: treat the string as an argument to avoid this
(void) fprintf(stderr,nomem_msg);
^
"%s",
3 warnings generated.
/usr/bin/xcrun -sdk macosx10.14 clang++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE -I"/Applications/Polyspace/R2020a/extern/include" -I"/Applications/Polyspace/R2020a/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -fobjc-arc -std=c++11 -stdlib=libc++ -O2 -fwrapv -DNDEBUG "/Applications/Polyspace/R2020a/extern/version/cpp_mexapi_version.cpp" -o /var/folders/8q/gj54rs5s6cv3whdzmhkf79_m0000gn/T/mex_1719808412277515_56763/cpp_mexapi_version.o
/usr/bin/xcrun -sdk macosx10.14 clang++ -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.9 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -framework Cocoa -bundle -stdlib=libc++ -O -Wl,-exported_symbols_list,"/Applications/Polyspace/R2020a/extern/lib/maci64/mexFunction.map" -Wl,-exported_symbols_list,"/Applications/Polyspace/R2020a/extern/lib/maci64/c_exportsmexfileversion.map" -Wl,-U,_mexCreateMexFunction -Wl,-U,_mexDestroyMexFunction -Wl,-U,_mexFunctionAdapter -Wl,-exported_symbols_list,"/Applications/Polyspace/R2020a/extern/lib/maci64/cppMexFunction.map" /var/folders/8q/gj54rs5s6cv3whdzmhkf79_m0000gn/T/mex_1719808412277515_56763/correspondPixels.o /var/folders/8q/gj54rs5s6cv3whdzmhkf79_m0000gn/T/mex_1719808412277515_56763/cpp_mexapi_version.o -L"/Applications/Polyspace/R2020a/bin/maci64" -lmx -lmex -lmat -L"/Applications/Polyspace/R2020a/extern/bin/maci64" -lMatlabDataArray -lMatlabEngine -o correspondPixels.mexmaci64
error using mex
Undefined symbols for architecture x86_64:
"matchEdgeMaps(Matrix const&, Matrix const&, double, double, Matrix&, Matrix&)",
referenced from:
_mexFunction in correspondPixels.o
"Matrix::data()", referenced from:
_mexFunction in correspondPixels.o
"Matrix::Matrix(int, int, double*)", referenced from:
_mexFunction in correspondPixels.o
"Matrix::Matrix()", referenced from:
_mexFunction in correspondPixels.o
"Matrix::~Matrix()", referenced from:
_mexFunction in correspondPixels.o
"Matrix::numel() const", referenced from:
_mexFunction in correspondPixels.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Anybody know how to solve this problem? maybe I'm not include some libraries to link to these functions but how could I find which libraries? I don't have any idea.Thanks for any help anyone can give.
I have written a few c++ function for integration into an R package by Rcpp, and these functions reply on the boost filesystem library. I have specified these in src/Makevar:
PKG_LIBS = -lboost_system -lboost_filesystem
And the package compiles ok:
==> R CMD INSTALL --preclean --no-multiarch --with-keep.source txtutils2
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c RcppExports.cpp -o RcppExports.o
* installing to library ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library’
* installing *source* package ‘txtutils2’ ...
** libs
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c bedcollc.cpp -o bedcollc.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c bedcollr.cpp -o bedcollr.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c countlines.cpp -o countlines.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c fileSize.cpp -o fileSize.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c ncols.cpp -o ncols.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c printlines.cpp -o printlines.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c readbed.cpp -o readbed.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c readcol.cpp -o readcol.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c readcols.cpp -o readcols.o
clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o txtutils2.so RcppExports.o bedcollc.o bedcollr.o countlines.o fileSize.o ncols.o printlines.o readbed.o readcol.o readcols.o -lboost_system -lboost_filesystem -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/3.1/Resources/library/txtutils2/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (txtutils2)
But when I try to load it, something goes wrong:
> library(txtutils2)
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/txtutils2/libs/txtutils2.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/txtutils2/libs/txtutils2.so, 6): Library not loaded: libboost_system.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/txtutils2/libs/txtutils2.so
Reason: image not found
Error: package or namespace load failed for ‘txtutils2’
I am on osx 10.10, if that matters.
General instructions on usage of external shared libs in R is also most welcome.
As far as I know, what you have met is not the problem of Rcpp even not the problem of R. It may be about linking on OSX.
I don't use Mac, so I just give you some advice. Try
otool -L yourpackagename.so
You should see a link to the boost library you use. You need to check whether the path is right.
I am working on a project developed under matlab, but I had to use C ++ and OpenCV.
In order to integrate my work with the project, I need to use mex-files. So I installed Matlab 2013 on my computer and gcc 4.4.
I modified the file ~/.matlab/R2013a/mexopts.sh in order to set the right compiler and options for opencv.
This is the output of the compilation in matlab with mex -v
**************************************************************************
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 = /home/amine/.matlab/R2013a/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /usr/local/MATLAB/R2013a
-> CC = gcc-4.4
-> CC flags:
CFLAGS = -std=c99 -D_GNU_SOURCE `pkg-config --cflags opencv` -fexceptions -fPIC -fno-omit-frame-pointer -pthread
CDEBUGFLAGS = -g
COPTIMFLAGS = -O -DNDEBUG
CLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2013a/bin/glnxa64 -L/usr/local/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
arguments = -DMX_COMPAT_32
-> CXX = g++-4.4
-> CXX flags:
CXXFLAGS = -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O -DNDEBUG
CXXLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2013a/bin/glnxa64 -L/usr/local/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2013a/bin/glnxa64 -L/usr/local/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> LD = g++-4.4
-> Link flags:
LDFLAGS = -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2013a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_ocl.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so /usr/lib/x86_64-linux-gnu/libXext.so /usr/lib/x86_64-linux-gnu/libX11.so /usr/lib/x86_64-linux-gnu/libICE.so /usr/lib/x86_64-linux-gnu/libSM.so /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so -ltbb -lrt -lpthread -lm -ldl
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexa64
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "mxFunction.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "verifAndHyp.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../Description/Statistic/statistic.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../Description/Statistic/classes.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../Verification/contradiction.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../HypothesisGeneration/hypothesis.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../Description/HoughTransform/hough.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../Description/HoughTransform/utils.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../Verification/distance.cpp"
-> g++-4.4 -O -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2013a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_ocl.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so /usr/lib/x86_64-linux-gnu/libXext.so /usr/lib/x86_64-linux-gnu/libX11.so /usr/lib/x86_64-linux-gnu/libICE.so /usr/lib/x86_64-linux-gnu/libSM.so /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so -ltbb -lrt -lpthread -lm -ldl -o "mxFunction.mexa64" mxFunction.o verifAndHyp.o statistic.o classes.o contradiction.o hypothesis.o hough.o utils.o distance.o -Wl,-rpath-link,/usr/local/MATLAB/R2013a/bin/glnxa64 -L/usr/local/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm
But when I try to use the mxFunction like this mxFunction('path_to_my_file'), the result is :
Invalid MEX-file '/home/amine/Stage2A/stage2a/src/HypothesisGeneration/mxFunction.mexa64': /usr/local/lib/libopencv_ocl.so.2.4: undefined symbol:
_ZTIN2cv16ParallelLoopBodyE
Could you help to resolv this problem ?
PS : I'm using ubuntu 14.04 and Opencv 2.4.8
If you would like to compile a C/C++ file containing OpenCV code into a MEX-file I strongly recommend that you use mexOpenCV instead of mex.
Have a look at this site to set it up properly:
http://de.mathworks.com/help/vision/ug/opencv-interface.html?refresh=true
It tells you how to install the visionSupportPackages which are mandatory to compile OpenCV code into a mex file.
I'm trying to compile a C++ file (mysql.cpp) in MATLAB with MEX Function on Linux server.
I'm getting this error which I'm not able to figure out why?
/opt/MATLAB/R2013a/bin/mex: line 1343: g++: command not found
mex: compile of ' "mysql.cpp"' failed.
I use this command:
mex -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient mysql.cpp
and here are the MEX Compiler Configuration Details: -
-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
FILE = /root/.matlab/R2013a/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /opt/MATLAB/R2013a
-> 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,/opt/MATLAB/R2013a/bin/glnxa64 -L/opt/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
arguments = -DMX_COMPAT_32
-> CXX = g++
-> CXX flags:
CXXFLAGS = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O -DNDEBUG
CXXLIBS = -Wl,-rpath-link,/opt/MATLAB/R2013a/bin/glnxa64 -L/opt/MATLAB/R2013a
/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -Wl,-rpath-link,/opt/MATLAB/R2013a/bin/glnxa64 -L/opt/MATLAB/R2013a
/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> LD = g++
-> Link flags:
LDFLAGS = -pthread -shared -Wl,--version-script,/opt/MATLAB/R2013a/extern
/lib/glnxa64/mexFunction.map -Wl,--no-undefined
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexa64
arguments = -Lusr/lib/mysql -lmysqlclient
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments = -Lusr/lib/mysql -lmysqlclient
Please help me to find out what is wrong.
Yeah, you should install a compiler before compiling. Mex is just a tool which calls one underneath and since g++ is the C++ compiler of gcc you should install this one.
As far as I know it will still not work, because matlab supports only gcc 4.3 (not sure about that). So install a gcc and run
mex -setup
Afterwards you should be able to compile.