我正在编译一些CUDA / C在Matlab中作为MEX库运行,我收到以下错误:
Error using mex
/usr/lib/x86_64-linux-gnu/libc_nonshared.a(atexit.oS): In function `atexit':
(.text+0x12): undefined reference to `__cxa_atexit'
collect2: error: ld returned 1 exit status
我假设这意味着我需要链接一些额外的库,但是什么?
我当前的编译命令是:
mex -L/usr/local/cuda/lib64 -lcudart -I./ A.cpp B.cpp C.cu D.cpp
我有几个内核可以编译成mex,有趣的是其中一些是有效的,有些则没有。我没有立即看出他们之间有什么区别 - 我当然不会在我的来源的任何地方打电话给atexit
。
这是详细的mex的输出:
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 'nvcc' ...
... Looking for environment variable 'MW_NVCC_PATH' ...Yes ('/usr/local/cuda-6.5/bin/nvcc').
... Looking for folder '/usr/local/cuda-6.5/bin' ...Yes.
... Looking for file '/usr/local/cuda-6.5/bin/nvcc' ...Yes.
... Executing command 'which g++' ...Yes ('/usr/bin/g++').
... Executing command 'g++ -print-file-name=libstdc++.so' ...Yes ('/usr/lib/gcc/x86_64-linux-gnu/4.8/libstdc++.so').
Found installed compiler 'nvcc'.
Options file details
-------------------------------------------------------------------
Compiler location: /usr/local/cuda-6.5/bin/nvcc
Options file: /home/nick/Documents/FrameLab/matlab/mex/source codes/mex_CUDA_glnxa64.xml
CMDLINE2 : /usr/bin/g++ -pthread -Wl,--no-undefined -shared -O -Wl,--version-script,"/usr/local/MATLAB/R2014a/extern/lib/glnxa64/mexFunction.map" /tmp/mex_86382821022260_3849/Atx_fan_mf.o /tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new.o /tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new_fb.o /tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new.o /tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new_fb.o /tmp/mex_86382821022260_3849/find_l.o /tmp/mex_86382821022260_3849/find_area.o -lcudart -L/usr/local/cuda/lib64 -Wl,-rpath-link,/usr/local/MATLAB/R2014a/bin/glnxa64 -L"/usr/local/MATLAB/R2014a/bin/glnxa64" -lmx -lmex -lmat -lm -lmwgpu /usr/local/MATLAB/R2014a/bin/glnxa64/libcudart.so.5.5 -o Atx_fan_mf.mexa64
CXX : /usr/local/cuda-6.5/bin/nvcc
DEFINES : -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
NVCCFLAGS : -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS
CXXFLAGS : --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread
INCLUDE : -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/"
CXXOPTIMFLAGS : -O -DNDEBUG
CXXDEBUGFLAGS : -g
LDXX : /usr/bin/g++
LDFLAGS : -pthread -Wl,--no-undefined
LDTYPE : -shared
LINKEXPORT : -Wl,--version-script,"/usr/local/MATLAB/R2014a/extern/lib/glnxa64/mexFunction.map"
LINKLIBS : -lcudart -L/usr/local/cuda/lib64 -Wl,-rpath-link,/usr/local/MATLAB/R2014a/bin/glnxa64 -L"/usr/local/MATLAB/R2014a/bin/glnxa64" -lmx -lmex -lmat -lm -lmwgpu /usr/local/MATLAB/R2014a/bin/glnxa64/libcudart.so.5.5
LDOPTIMFLAGS : -O
LDDEBUGFLAGS : -g
OBJEXT : .o
LDEXT : .mexa64
NVCC : /usr/local/cuda-6.5/bin/nvcc
GCC : /usr/bin/g++
CPPLIB_DIR : /usr/lib/gcc/x86_64-linux-gnu/4.8/libstdc++.so
MATLABROOT : /usr/local/MATLAB/R2014a
ARCH : glnxa64
SRC : "/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf.cpp";"/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf_gpu_new.cu";"/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf_gpu_new_fb.cu";"/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf_cpu_new.cpp";"/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf_cpu_new_fb.cpp";"/home/nick/Documents/FrameLab/matlab/mex/source codes/find_l.cpp";"/home/nick/Documents/FrameLab/matlab/mex/source codes/find_area.cpp"
OBJ : /tmp/mex_86382821022260_3849/Atx_fan_mf.o;/tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new.o;/tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new_fb.o;/tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new.o;/tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new_fb.o;/tmp/mex_86382821022260_3849/find_l.o;/tmp/mex_86382821022260_3849/find_area.o
OBJS : /tmp/mex_86382821022260_3849/Atx_fan_mf.o /tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new.o /tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new_fb.o /tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new.o /tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new_fb.o /tmp/mex_86382821022260_3849/find_l.o /tmp/mex_86382821022260_3849/find_area.o
SRCROOT : /home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf
DEF : /tmp/mex_86382821022260_3849/Atx_fan_mf.def
EXP : Atx_fan_mf.exp
LIB : Atx_fan_mf.lib
EXE : Atx_fan_mf.mexa64
ILK : Atx_fan_mf.ilk
MANIFEST : Atx_fan_mf.mexa64.manifest
TEMPNAME : Atx_fan_mf
EXEDIR :
EXENAME : Atx_fan_mf
OPTIM : -O -DNDEBUG
LINKOPTIM : -O
CMDLINE1_0 : /usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf.cpp" -o /tmp/mex_86382821022260_3849/Atx_fan_mf.o
CMDLINE1_1 : /usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf_gpu_new.cu" -o /tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new.o
CMDLINE1_2 : /usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf_gpu_new_fb.cu" -o /tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new_fb.o
CMDLINE1_3 : /usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf_cpu_new.cpp" -o /tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new.o
CMDLINE1_4 : /usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf_cpu_new_fb.cpp" -o /tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new_fb.o
CMDLINE1_5 : /usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/find_l.cpp" -o /tmp/mex_86382821022260_3849/find_l.o
CMDLINE1_6 : /usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/find_area.cpp" -o /tmp/mex_86382821022260_3849/find_area.o
CMDLINE3_0 : rm -f /tmp/mex_86382821022260_3849/Atx_fan_mf.o
CMDLINE3_1 : rm -f /tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new.o
CMDLINE3_2 : rm -f /tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new_fb.o
CMDLINE3_3 : rm -f /tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new.o
CMDLINE3_4 : rm -f /tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new_fb.o
CMDLINE3_5 : rm -f /tmp/mex_86382821022260_3849/find_l.o
CMDLINE3_6 : rm -f /tmp/mex_86382821022260_3849/find_area.o
-------------------------------------------------------------------
Building with 'nvcc'.
/usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf.cpp" -o /tmp/mex_86382821022260_3849/Atx_fan_mf.o
/usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf_gpu_new.cu" -o /tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new.o
/usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf_gpu_new_fb.cu" -o /tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new_fb.o
/usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf_cpu_new.cpp" -o /tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new.o
/usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/Atx_fan_mf_cpu_new_fb.cpp" -o /tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new_fb.o
/usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/find_l.cpp" -o /tmp/mex_86382821022260_3849/find_l.o
/usr/local/cuda-6.5/bin/nvcc -c -DMX_COMPAT_32 --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I./ -I"/usr/local/MATLAB/R2014a/extern/include" -I"/usr/local/MATLAB/R2014a/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG "/home/nick/Documents/FrameLab/matlab/mex/source codes/find_area.cpp" -o /tmp/mex_86382821022260_3849/find_area.o
/usr/bin/g++ -pthread -Wl,--no-undefined -shared -O -Wl,--version-script,"/usr/local/MATLAB/R2014a/extern/lib/glnxa64/mexFunction.map" /tmp/mex_86382821022260_3849/Atx_fan_mf.o /tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new.o /tmp/mex_86382821022260_3849/Atx_fan_mf_gpu_new_fb.o /tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new.o /tmp/mex_86382821022260_3849/Atx_fan_mf_cpu_new_fb.o /tmp/mex_86382821022260_3849/find_l.o /tmp/mex_86382821022260_3849/find_area.o -lcudart -L/usr/local/cuda/lib64 -Wl,-rpath-link,/usr/local/MATLAB/R2014a/bin/glnxa64 -L"/usr/local/MATLAB/R2014a/bin/glnxa64" -lmx -lmex -lmat -lm -lmwgpu /usr/local/MATLAB/R2014a/bin/glnxa64/libcudart.so.5.5 -o Atx_fan_mf.mexa64
我想知道我是否应该尝试使用不同版本的g ++或c ++库?我不确定如何更改CPPLIB_DIR
变量...... Matlab让2014年的mex设置变得更加困难。
感谢您的任何想法!
答案 0 :(得分:1)
我在使用CUDA 6.5和g ++ 4.8的Ubuntu 14.04上使用Matlab 2015 Prerelease时遇到了同样的错误。感谢Matlab的支持,我们发现,手动链接可以解决问题。这是我的matlab mex / gpu示例的编译脚本:
myArch = computer('arch'); pathToOpts = fullfile(matlabroot, ... 'toolbox', 'distcomp', 'gpu', ... 'extern', 'src', 'mex', myArch,'gcc',... ['mex_CUDA_' myArch '.xml']); copyfile(pathToOpts,'.','f')
mex -v -largeArrayDims mexGPUExample.cu -lstdc++ -lc