How to link during Matlab's MEX compilation

后端 未结 3 1958
春和景丽
春和景丽 2020-12-10 16:44

I\'ve written a program of the following form:

#include \"stuff_I_need.h\"

int main(){

construct_array(); // uses OpenMP pragma\'s
print_array();

return(0         


        
相关标签:
3条回答
  • 2020-12-10 17: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
    
    0 讨论(0)
  • 2020-12-10 17:35

    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.

    0 讨论(0)
  • 2020-12-10 17:43

    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.

    0 讨论(0)
提交回复
热议问题