Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我编写了以下形式的程序:
#include "stuff_I_need.h" int main(){ construct_array(); // uses OpenMP pragma's print_array(); return(0); } 可以使用以下命令编译,链接并正常运行: `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”只是gcc版本4.4,因此命名为“ gcc44”,因为它是在维护多个gcc版本的集群上编译的。在数组构造过程中,库sundials_cvode和sundials_nvecserial用于解决几个微分方程。 现在,当我想转移到Matlab并尝试编译表单的mex文件时: #include "stuff_I_need.h" void mexFunction(int nlhs,mxArray* plhs[], int nrhs, const mxArray* prhs[]){ construct_array(); // uses OpenMP pragma's print_array(); } 并尝试在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 我收到以下消息,最终导致链接错误: -> 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/com...rrent_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. 不知何故,我没有提供正确的标志来正确链接。如果我删除了gcc44命令中链接的命令,则会遇到相同的错误(还有更多错误),所以我很确定自己不会让编译器“看到”这些库。 我的问题是:
最后,我确实需要版本4.4,因为某些OpenMP支持在以前的版本中没有出现。 在此先感谢您的帮助。 - 安德鲁 编辑:(@KWATFORD) 因此,我尝试使用引号外的语句执行命令,并得到以下错误: -> 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. 对于“ -fPIC”重新编译的建议,我有些困惑,因为当我查看gcc44命令时,我将-fPIC作为选项。 他们是说要用-fPIC重新编译该库吗? 我没有该库的源代码,如果建议重新编译该库,是否有解决方法? “针对本地对象的重定位”是什么意思? 我继续表示感谢。 回答: 尽量不要将-l , -L或-I参数放在这些环境变量中。 mex函数将直接处理这些类型的参数。所以也许像这样: 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 更多&回答... |
![]() |
![]() |