Problem compiling old C code and using old dll file in Matlab r2016a

5 views (last 30 days)
Hi, I am trying to run a program for a pretty old Nature paper (published in 1996). I download the source code (Windows version "WinSparsNet.zip") from http://redwood.berkeley.edu/bruno/sparsenet/, and I had 64bit Matlab r2016a student version with MinGW64 Compiler installed.
I need to load one "cgf.dll" file provided in the downloaded folder, and I use the loadlibrary function. However, I didn't see any header file in the folder, only found "cgf.c" and "cgf.map" files. So I tried
loadlibrary('cgf.dll','cgf.c')
Then Matlab returned:
Error using loadlibrary
Failed to preprocess the input file.
Output from preprocessor is:C:\Users\***\Documents\MATLAB\Sparsenet\cgf.c:208:20: fatal error: nrutil.h: No such file or directory
#include <nrutil.h>
^
compilation terminated.
I found the "nrutil.h" file in a subfolder of the download file, and then I copied it to "C:\Program Files\MATLAB\R2016a\extern\include", tried the above command again, and Matlab returned a even longer error:
Warning: Warnings messages were produced while parsing. Check the functions you intend to use for correctness. Warning text can be viewed using:
[notfound,warnings]=loadlibrary(...)
> In loadlibrary
Error loading library intermediate output follows.
The actual error is at the end of this output.
*********
found parens in x ; unsigned long long val ; __extension__ struct { unsigned int low , high ; } lh ; } __mingw_dbl_type_t
Match: unsigned int low , high ;
Final string:x ; unsigned long long val ; __extension__ struct lh ; } __mingw_dbl_type_t
Failed to parse type 'union __mingw_dbl_type_t { double x ; unsigned long long val ; __extension__ struct { unsigned int low , high ; } lh ; } __mingw_dbl_type_t' original input 'union __mingw_dbl_type_t { double x ; unsigned long long val ; __extension__ struct { unsigned int low , high ; } lh ; } __mingw_dbl_type_t'
Found on line 673 of input from line 90 of file C:/MATLAB/SupportPackages/R2016a/MW_MinGW_4_9/x86_64-w64-mingw32/include/math.h
Failed to parse type 'union __mingw_flt_type_t { float x ; unsigned int val ; } __mingw_flt_type_t' original input 'union __mingw_flt_type_t { float x ; unsigned int val ; } __mingw_flt_type_t'
Found on line 678 of input from line 95 of file C:/MATLAB/SupportPackages/R2016a/MW_MinGW_4_9/x86_64-w64-mingw32/include/math.h
found parens in x ; __extension__ struct { unsigned int low , high ; int sign_exponent : 16 ; int res1 : 16 ; int res0 : 32 ; } lh ; } __mingw_ldbl_type_t
Match: unsigned int low , high ; int sign_exponent : 16 ; int res1 : 16 ; int res0 : 32 ;
Final string:x ; __extension__ struct lh ; } __mingw_ldbl_type_t
Failed to parse type 'union __mingw_ldbl_type_t { long double x ; __extension__ struct { unsigned int low , high ; int sign_exponent : 16 ; int res1 : 16 ; int res0 : 32 ; } lh ; } __mingw_ldbl_type_t' original input 'union __mingw_ldbl_type_t { long double x ; __extension__ struct { unsigned int low , high ; int sign_exponent : 16 ; int res1 : 16 ; int res0 : 32 ; } lh ; } __mingw_ldbl_type_t'
Found on line 689 of input from line 106 of file C:/MATLAB/SupportPackages/R2016a/MW_MinGW_4_9/x86_64-w64-mingw32/include/math.h
Type 'longdouble' was not found. Defaulting to type error.
Found on line 1184 of input from line 85 of file C:/MATLAB/SupportPackages/R2016a/MW_MinGW_4_9/x86_64-w64-mingw32/include/stdlib.h
Type 'longlong__extension__' was not found. Defaulting to type error.
Found on line 1558 of input from line 626 of file C:/MATLAB/SupportPackages/R2016a/MW_MinGW_4_9/x86_64-w64-mingw32/include/stdlib.h
Type 'longlong__extension__' was not found. Defaulting to type error.
Found on line 1558 of input from line 626 of file C:/MATLAB/SupportPackages/R2016a/MW_MinGW_4_9/x86_64-w64-mingw32/include/stdlib.h
Type '_mexLocalFunctionTablePtr' was not found. Defaulting to type voidPtr.
Found on line 2665 of input from line 81 of file C:\\Program Files\\MATLAB\\R2016a\\extern\\include/mex.h
Type 'ITMAX' was not found. Defaulting to type error.
Found on line 3138 of input from line 210 of file C:\\Users\\***\\Documents\\MATLAB\\Sparsenet\\cgf.c
*********
Error using loadlibrary
Building cgf_thunk_pcwin64 failed. Compiler output is:
C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\bin\gcc -I"C:\Program Files\MATLAB\R2016a\extern\include" -fexceptions -fno-omit-frame-pointer
-I"C:\Users\***\Documents\MATLAB\Sparsenet" -I"C:\Users\***\Documents\MATLAB\Sparsenet" "cgf_thunk_pcwin64.c" -o "cgf_thunk_pcwin64.dll"
-shared
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0x830): undefined reference to `__imp_ITMAX'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0x84d): undefined reference to `vector'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xa53): undefined reference to `frprmn'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xbc6): undefined reference to `free_vector'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xc24): undefined reference to `mexErrMsgTxt'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xc38): undefined reference to `mexErrMsgTxt'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xc47): undefined reference to `mxGetPr'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xc61): undefined reference to `mxGetPr'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xc78): undefined reference to `mxGetPr'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xc8f): undefined reference to `mxGetScalar'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xcae): undefined reference to `mxGetScalar'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xccd): undefined reference to `mxGetScalar'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xd02): undefined reference to `mxGetScalar'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xd2d): undefined reference to `mxGetScalar'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xd59): more undefined references to `mxGetScalar' follow
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xd9b): undefined reference to `mxGetM'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xdb0): undefined reference to `mxGetN'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xdc9): undefined reference to `mxGetN'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xde8): undefined reference to `mxCreateDoubleMatrix_730'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xe01): undefined reference to `mxGetPr'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xe28): undefined reference to `mxCreateDoubleMatrix_730'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xe4e): undefined reference to `mxCreateDoubleMatrix_730'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xe74): undefined reference to `mxCreateDoubleMatrix_730'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xed5): undefined reference to `mxGetPr'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xef8): undefined reference to `mxGetPr'
C:\Users\***\AppData\Local\Temp\cc4JyfCI.o:cgf_thunk_pcwin64.c:(.text+0xf1b): undefined reference to `mxGetPr'
collect2.exe: error: ld returned 1 exit status
I am not a experienced program compiler at all. I just want to reproduce the results in that old paper. The authors had already post the code online, so there must be a way to run it. Anyone know how to overcome the current issues?

Answers (0)

Categories

Find more on MATLAB Compiler SDK in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!