Comment lier au cours de Matlab MEX compilation

J'ai écrit un programme de la forme suivante:

#include "stuff_I_need.h"

int main(){

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

return(0);


}

qui compile, des liens, et fonctionne correctement avec la commande suivante:

`gcc44 -I/home/matteson/sundials/include/ main.c -lm -L/home/matteson/sundials/lib -lsundials_cvode -lsundials_nvecserial -fopenmp -o /home/matteson/MPI_test/CVODE_test/main_test`

"gcc44" est tout simplement la version de gcc 4.4 et est nommé ainsi parce qu'il est compilé sur un cluster qui maintient plusieurs versions de gcc. Les bibliothèques sundials_cvode et sundials_nvecserial sont utilisés dans la résolution de plusieurs équations différentielles lors de la construction de la matrice.

Maintenant, quand je veux transférer sur Matlab et essayez de compiler le mex fichier de la forme:

#include "stuff_I_need.h"

void mexFunction(int nlhs,mxArray* plhs[], int nrhs, const mxArray* prhs[]){

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

}

et d'essayer de compiler avec la commande suivante dans Matlab:

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

J'obtiens les messages suivants aboutissant à une erreur de lien:

    -> mexopts.sh sourced from directory (DIR = $HOME/.matlab/$REL_VERSION)
FILE = /home/matteson/.matlab/R2010b/mexopts.sh
----------------------------------------------------------------
->    MATLAB                = /misc/linux/64/opt/pkg/matlab/R2010b
->    CC                    = gcc44
->    CC flags:
CFLAGS             = -ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread -I/home/matteson/sundials/include/ -L/home/matteson/sundials/lib -lsundials_cvode -L/home/matteson/sundials/lib -lsundials_nvecserial
CDEBUGFLAGS        = -g
COPTIMFLAGS        = -O -DNDEBUG
CLIBS              = -Wl,-rpath-link,/misc/linux/64/opt/pkg/matlab/R2010b/bin/glnxa64 -L/misc/linux/64/opt/pkg/matlab/R2010b/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,/misc/linux/64/opt/pkg/matlab/R2010b/bin/glnxa64 -L/misc/linux/64/opt/pkg/matlab/R2010b/bin/glnxa64 -lmx -lmex -lmat -lm
arguments          =  -DMX_COMPAT_32
->    FC                    = g95
->    FC flags:
FFLAGS             = -fexceptions -fPIC -fno-omit-frame-pointer
FDEBUGFLAGS        = -g
FOPTIMFLAGS        = -O
FLIBS              = -Wl,-rpath-link,/misc/linux/64/opt/pkg/matlab/R2010b/bin/glnxa64 -L/misc/linux/64/opt/pkg/matlab/R2010b/bin/glnxa64 -lmx -lmex -lmat -lm
arguments          =  -DMX_COMPAT_32
->    LD                    = gcc44
->    Link flags:
LDFLAGS            = -pthread -shared -Wl,--version-script,/misc/linux/64/opt/pkg/matlab/R2010b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -fopenmpofopenmp
LDDEBUGFLAGS       = -g
LDOPTIMFLAGS       = -O
LDEXTENSION        = .mexa64
arguments          = 
->    LDCXX                 = 
->    Link flags:
LDCXXFLAGS         = 
LDCXXDEBUGFLAGS    = 
LDCXXOPTIMFLAGS    = 
LDCXXEXTENSION     = 
arguments          = 
----------------------------------------------------------------
Warning: You are using gcc version "4.4.4".  The version
currently supported with MEX is "4.3.4".
For a list of currently supported compilers see: 
http://www.mathworks.com/support/compilers/current_release/
-> gcc44 -c  -I/misc/linux/64/opt/pkg/matlab/R2010b/extern/include -I/misc/linux/64/opt/pkg/matlab/R2010b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread -I/home/matteson/sundials/include/ -L/home/matteson/sundials/lib -lsundials_cvode -L/home/matteson/sundials/lib -lsundials_nvecserial  -DMX_COMPAT_32 -O -DNDEBUG  "mex_cvode.c"
-> gcc44 -O -pthread -shared -Wl,--version-script,/misc/linux/64/opt/pkg/matlab/R2010b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -fopenmpofopenmp -o  "mex_cvode.mexa64"  mex_cvode.o  -Wl,-rpath-link,/misc/linux/64/opt/pkg/matlab/R2010b/bin/glnxa64 -L/misc/linux/64/opt/pkg/matlab/R2010b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
mex_cvode.o: In function `mexFunction':
mex_cvode.c:(.text+0x2b2): undefined reference to `N_VNew_Serial'
mex_cvode.c:(.text+0x2db): undefined reference to `N_VNew_Serial'
mex_cvode.c:(.text+0x35b): undefined reference to `CVodeCreate'
mex_cvode.c:(.text+0x39c): undefined reference to `CVodeInit'
mex_cvode.c:(.text+0x3dd): undefined reference to `CVodeSVtolerances'
mex_cvode.c:(.text+0x412): undefined reference to `CVodeSetUserData'
mex_cvode.c:(.text+0x449): undefined reference to `CVDense'
mex_cvode.c:(.text+0x482): undefined reference to `CVDlsSetDenseJacFn'
mex_cvode.c:(.text+0x50c): undefined reference to `CVode'
mex_cvode.c:(.text+0x5b4): undefined reference to `N_VDestroy_Serial'
mex_cvode.c:(.text+0x5c0): undefined reference to `N_VDestroy_Serial'
mex_cvode.c:(.text+0x5cc): undefined reference to `CVodeFree'
collect2: ld returned 1 exit status
mex: link of ' "mex_cvode.mexa64"' failed.
??? Error using ==> mex at 208
Unable to complete successfully.

En quelque sorte, je ne suis pas en mesure de donner les bonnes drapeaux de lier de façon appropriée. Comme je reçois le même ensemble d'erreurs (plus quelques autres), si je retire les commandes de lien dans le gcc44 commande, je suis assez sûr que je ne suis pas le compilateur de "voir" les bibliothèques.

Mes questions sont :

  • Si mon analyse de l'erreur est correcte, ce que les drapeaux de faire j'ai besoin de passer à la mex compilation de commande avec succès lien?
  • Sinon, quels sont les gcc drapeaux pour compiler et lier à l'extérieur de l'environnement pour compiler un .mex64 de l'exécutable?
  • Si mon analyse est fausse, où aller à partir d'ici?

Je pense que j'ai écarté la non prise en charge d'avertissement du compilateur depuis que j'ai été en mesure de compiler simple mex avec OpenMP programmes à l'aide de gcc 4.4, mais elles n'ont pas de lien contre quoi que ce soit à l'exception de la bibliothèque de mathématiques. Aussi, si je compile avec la version de gcc version 4.1.2 ou 4.3.4 avec ou sans le "-fopenmp" drapeaux, j'obtiens la même erreur.

À la fin, je n'ai besoin de la version 4.4 en raison de certaines OpenMP soutien qui ne figurent pas dans les versions antérieures.

Merci d'avance pour l'aide.

- Andrew

Modifications: (@KWATFORD)

J'ai donc essayé la commande avec les états en dehors de l'citations et obtenu l'erreur:

-> gcc44 -c  -I/home/matteson/sundials/include/ -I/misc/linux/64/opt/pkg/matlab/R2010b/extern/include -I/misc/linux/64/opt/pkg/matlab/R2010b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread -fopenmp  -DMX_COMPAT_32 -O -DNDEBUG  "mex_cvode.c"
-> gcc44 -O -pthread -shared -Wl,--version-script,/misc/linux/64/opt/pkg/matlab/R2010b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -fopenmp -o  "mex_cvode.mexa64"  mex_cvode.o  -L/home/matteson/sundials/lib -lsundials_cvode -lsundials_nvecserial -Wl,-rpath-link,/misc/linux/64/opt/pkg/matlab/R2010b/bin/glnxa64 -L/misc/linux/64/opt/pkg/matlab/R2010b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
/usr/bin/ld: /home/matteson/sundials/lib/libsundials_cvode.a(cvode.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/home/matteson/sundials/lib/libsundials_cvode.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
mex: link of ' "mex_cvode.mexa64"' failed.
??? Error using ==> mex at 208
Unable to complete successfully.

Je suis un peu confus au sujet de la suggestion de recompiler avec-fPIC" parce que quand je regarde la gcc44 de commande je vois le fPIC comme une option.

Disent-ils à recompiler la bibliothèque avec -fPIC?

Je n'ai pas la source de la bibliothèque, si la suggestion est de recompiler la bibliothèque est-il une solution?

Qu'est la "délocalisation à l'encontre de l'objet local"?

Ma grâce.

OriginalL'auteur Sevenless | 2011-02-07