How to link during Matlab's MEX compilation

瘦欲@ 提交于 2019-11-28 11:21:21

Try not putting the -l, -L, or -I arguments in those environment variables. The mex function will handle those types of arguments directly. So perhaps something like:

mex -v CC="gcc44" CFLAGS="\$CFLAGS -fopenmp" LDFLAGS="\$LDFLAGS -fopenmp" -I/home/matteson/sundials/include/ -L/home/matteson/sundials/lib -lsundials_cvode -lsundials_nvecserial mex_cvode.c

Kwatford put me on the right track with the second question. I was able to get the mex command to work by rebuilding the sundials solver with shared libraries. Specifically, I built with:

% make distclean
% ./configure --prefix=/home/matteson/sundials --enable-shared
% make
% make install

Also, thanks to kwatford for the fix to the original by calling:

mex -v CC="gcc44" CFLAGS="\$CFLAGS -fopenmp" LDFLAGS="\$LDFLAGS -fopenmp" -I/home/matteson/sundials/include/ -L/home/matteson/sundials/lib -lsundials_cvode -lsundials_nvecserial mex_cvode.c

since mex knows how to handle the -L and -I.

Matlab uses its own libstdc and libstdc++.

The shortcut would be to do a symbolink to those libraries to the gcc44 libraries that you want to use.

But this may not be the desired way to go. You could try compiling outside matlab prompt and see if it still fails compilation first.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!