How to get a clean CDT Build Console Output? - eclipse

I'm working with STM32CubeIDE using gcc compiler. In the build output I have to search for warnings and errors in a hundred lines of compiler-output infos. I'm explicitly interested in all warnings and errors! But I do not need something like this as there isn't any warning or error:
(Useful information)
arm-none-eabi-gcc "../gmem/wdog.c"
(followed by 912 useless bytes)
-mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DNUCLEO -DUSE_HAL_DRIVER -DSTM32F446xx -DUSE_FULL_LL_DRIVER -c -I"E:/STM32CubeIDE_11/fatl22_lcd/Ampel" -I../Core/Inc -I"E:/STM32CubeIDE_11/fatl22_lcd/lcd" -I"E:/STM32CubeIDE_11/fatl22_lcd/rtc" -I"E:/STM32CubeIDE_11/fatl22_lcd/so" -I"E:/STM32CubeIDE_11/fatl22_lcd/uart" -I"E:/STM32CubeIDE_11/fatl22_lcd/interrupts" -I"E:/STM32CubeIDE_11/fatl22_lcd/gmem" -I../Drivers/STM32F4xx_HAL_Driver/Inc -I"E:/STM32CubeIDE_11/fatl22_lcd/debugpins" -I"E:/STM32CubeIDE_11/fatl22_lcd/funk" -I"E:/STM32CubeIDE_11/fatl22_lcd/kabel" -I"E:/STM32CubeIDE_11/fatl22_lcd/scheduler" -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -Wconversion -fstack-usage -MMD -MP -MF"gmem/wdog.d" -MT"gmem/wdog.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "gmem/wdog.o"
How can I get rid of this crap ?
I searched for gcc option help files and some "how to increase verbosity" hoping to find the contrary ;-) .
I found explicit help for reducing warnings, which is not my intention.

Related

Linking OpenMP with Matlab mex files [duplicate]

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);
}
that compiles, links, and runs correctly with the following command:
`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" is simply gcc version 4.4 and is named like this because it's being compiled on a cluster that maintains several versions of gcc. The libraries sundials_cvode and sundials_nvecserial are used in the solving of several differential equations during the construction of the array.
Now when I want to transfer over to Matlab and try to compile the mex file of the form:
#include "stuff_I_need.h"
void mexFunction(int nlhs,mxArray* plhs[], int nrhs, const mxArray* prhs[]){
construct_array(); // uses OpenMP pragma's
print_array();
}
and try to compile with the following command in 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
I get the following messages culminating in a link error:
-> 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.
Somehow, I'm not giving the correct flags to link appropriately. As I get the same set of errors (plus a few more) if I remove the commands to link in the gcc44 command, I'm pretty sure that I'm not getting the compiler to "see" the libraries.
My questions are :
If my analysis of the error is correct, what flags do I need to pass to the mex compilation command to successfully link?
Alternatively, what are the gcc flags to compile and link outside of the Matlab environment to compile a .mex64 executable?
If my analysis is wrong, where to go from here?
I think I've ruled out the unsupported compiler warning since I've been able to compile simple mex with OpenMP programs using gcc 4.4, but these did not have to link against anything except the math library. Also, if I compile with version gcc version 4.1.2 or 4.3.4 with or without the "-fopenmp" flags I get the same error.
In the end I do need version 4.4 because of certain OpenMP support that did not appear in prior versions.
Thanks in advance for the help.
--Andrew
Edits: (#KWATFORD)
So I tried the command with the statements outside the the quotes, and got the error:
-> 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.
I'm a bit confused about the suggestion to recompile with "-fPIC" because when I look at the gcc44 command I see the -fPIC as an option.
Are they saying to recompile the library with -fPIC?
I don't have the source for the library, if the suggestion is to recompile the library is there a workaround?
What does "relocation against local object" mean?
My continued thanks.
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.

cortex-m3 fpu instruction hard fault

My firmware for stm32f103 results in hard fault.
Here is the line of code that crash execution:
float shuntResistance = p[SHUNT_RESISTANCE];
where p - is global array of floats:
float p[CONFIG_NUM_PARAMS];
There is dissaembly while debugging:
0800177c: ldr r3, [pc, #332] ; (0x80018cc <adcSetConstants+336>)
0800177e: vldr s10, [r3, #48] ; 0x30 ; on that instruction program results in hard fault
Here is compiler flags:
-c -fmessage-length=0 -mthumb -mcpu=cortex-m3 -mfloat-abi=softfp -ffunction-sections -fdata-sections -fsingle-precision-constant
Linker flags:
-Wl,--static,--gc-sections,-Map=${ProjName}.map,-T../stm32_flash.ld -fmessage-length=0 -mthumb -mcpu=cortex-m3 -ffunction-sections -fdata-sections -fsingle-precision-constant -Dprintf=iprintf -u _printf_float -lc -lnosys -lc
Used compiler is launchpad's arm-none-eabi-gcc.
Used IDE is eclipse.
What is the cause?
Here is compiler flags:
-c -fmessage-length=0 -mthumb -mcpu=cortex-m3 -mfloat-abi=softfp
Your MCU is a Cortex M3, which has no FPU. You need to use -mfloat-abi=soft. The "softfp" option uses FPU instructions which will not work for you.

C make file is really confusing me

I'm working on learning C from a family member who's very adept as far as I know.
I'm using MingW on windows 7 with a fresh install of windows and having some difficulties getting things to work properly. I've made a make file and am using Deitel C for programmers with an introduction to C11, and have typed up the examples from the book in chapter three. I'm fairly certain I've managed to get that portion correct, and the makefile I'm using seems to be correct but it gives me a strange error that I don't understand.
C -o ex01 -O3 -Wall -Werrors -static -pedantic-errors -g main.o
make: C: Command not found
make: * [ex01] Error 127
this is the exact error I keep getting, I'm not sure if there's something wrong with the makefile or if it's something wrong with settings...
RM=rm
CC=gcc
LINK=$CC
CFLAGS = -O3 -Wall -Werrors -static -pedantic-errors -g
all: main.o ex01
clean:
(Tab)$(RM) -f main.o ex01.exe
main.o: main.c
(Tab)$(CC) -o main.o $(CFLAGS) -c main.c
ex01: main.o
(Tab)$(LINK) -o ex01 $(CFLAGS) main.o
this is almost exactly the makefile I'm using, asside from the (Tab) in place of actual tabs. I hope this is enough information to get some help, I suspect it's something wrong with my settings, I've had to set up paths to my library and gcc location. I'm just not sure where else to set up a path that could rectify this error.
#Keltar's comment nailed it exactly: LINK=$CC should be LINK=$(CC).
In make's syntax, $() is the proper way to deference a variable. The line LINK=$(CC) means set the variable LINK to whatever the CC variable is set to. After that instruction, their values will be the same.

Not able to link libsvn_delta-1.a when compiling svn_swig_perl in msys

Trying to compile perl svn binding for msys. But when compiling the swig perl lib_core.dll it complains reference not found for _svn_delta_noop_window_handler and _svn_delta_default_editor in libsvn_swig_perl-1.a. Both function coming from libsvn_delta-1.a.
I should recompile and make sure the libsvn_swig_perl-1.a properly link with libsvn_delta-1.a? Or it doesn't matter as long as during building lib_core.dll it can link the missing static library?
I really have no idea how to solve this issue.
below are the full log when compile the lib_core.dll:
ld2 -s core.o -o blib/arch/auto/SVN/_Core/_Core.dll \
/usr/lib/perl5/5.8.8/msys/CORE/libperl.dll.a -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/bindings/swig/perl/libsvn_swig_perl/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_client/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_delta/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_repos/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_wc/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_diff/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_subr/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_local/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_svn/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_neon/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs_util/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs_fs/.libs -lsvn_client-1 -lsvn_delta-1 -lsvn_fs-1 -lsvn_ra-1 -lsvn_repos-1 -lsvn_wc-1 -lsvn_diff-1 -lsvn_subr-1 -lsvn_fs_util-1 -lsvn_swig_perl-1 -lapr-1 -lintl -lz -laprutil-1 -lexpat -lperl -L/lib/perl5/5.8.8/msys/CORE \
gcc -shared -o _Core.dll -Wl,--out-implib=lib_Core.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--stack,8388608 -Wl,--enable-auto-image-base \
-s core.o /usr/lib/perl5/5.8.8/msys/CORE/libperl.dll.a -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/bindings/swig/perl/libsvn_swig_perl/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_client/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_delta/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_repos/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_wc/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_diff/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_subr/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_local/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_svn/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_neon/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs_util/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs_fs/.libs -lsvn_client-1 -lsvn_delta-1 -lsvn_fs-1 -lsvn_ra-1 -lsvn_repos-1 -lsvn_wc-1 -lsvn_diff-1 -lsvn_subr-1 -lsvn_fs_util-1 -lsvn_swig_perl-1 -lapr-1 -lintl -lz -laprutil-1 -lexpat -lperl -L/lib/perl5/5.8.8/msys/CORE
Creating library file: lib_Core.dll.a
/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/bindings/swig/perl/libsvn_swig_perl/.libs/libsvn_swig_perl-1.a(swigutil_pl.o.b): In function `thunk_apply_textdelta':
/usr/src/subversion16/subversion-1.6.17-3-msys-src/subversion-1.6.17/subversion/bindings/swig/perl/libsvn_swig_perl/swigutil_pl.c:703: undefined reference to `_svn_delta_noop_window_handler'
/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/bindings/swig/perl/libsvn_swig_perl/.libs/libsvn_swig_perl-1.a(swigutil_pl.o.b): In function `svn_delta_make_editor':
/usr/src/subversion16/subversion-1.6.17-3-msys-src/subversion-1.6.17/subversion/bindings/swig/perl/libsvn_swig_perl/swigutil_pl.c:785: undefined reference to `_svn_delta_default_editor'
collect2: ld returned 1 exit status
perlld: *** system() failed to execute
gcc -shared -o _Core.dll -Wl,--out-implib=lib_Core.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--stack,8388608 -Wl,--enable-auto-image-base \
-s core.o /usr/lib/perl5/5.8.8/msys/CORE/libperl.dll.a -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/bindings/swig/perl/libsvn_swig_perl/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_client/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_delta/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_repos/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_wc/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_diff/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_subr/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_local/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_svn/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_neon/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs_util/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs_fs/.libs -lsvn_client-1 -lsvn_delta-1 -lsvn_fs-1 -lsvn_ra-1 -lsvn_repos-1 -lsvn_wc-1 -lsvn_diff-1 -lsvn_subr-1 -lsvn_fs_util-1 -lsvn_swig_perl-1 -lapr-1 -lintl -lz -laprutil-1 -lexpat -lperl -L/lib/perl5/5.8.8/msys/CORE
My question already answer by other post. Its the linker order issue. Check the answer below:
Linker order
I just need to move around the linker for svn_swig_perl to link it before svn_delta to solve the problem.

How to link during Matlab's MEX compilation

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);
}
that compiles, links, and runs correctly with the following command:
`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" is simply gcc version 4.4 and is named like this because it's being compiled on a cluster that maintains several versions of gcc. The libraries sundials_cvode and sundials_nvecserial are used in the solving of several differential equations during the construction of the array.
Now when I want to transfer over to Matlab and try to compile the mex file of the form:
#include "stuff_I_need.h"
void mexFunction(int nlhs,mxArray* plhs[], int nrhs, const mxArray* prhs[]){
construct_array(); // uses OpenMP pragma's
print_array();
}
and try to compile with the following command in 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
I get the following messages culminating in a link error:
-> 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.
Somehow, I'm not giving the correct flags to link appropriately. As I get the same set of errors (plus a few more) if I remove the commands to link in the gcc44 command, I'm pretty sure that I'm not getting the compiler to "see" the libraries.
My questions are :
If my analysis of the error is correct, what flags do I need to pass to the mex compilation command to successfully link?
Alternatively, what are the gcc flags to compile and link outside of the Matlab environment to compile a .mex64 executable?
If my analysis is wrong, where to go from here?
I think I've ruled out the unsupported compiler warning since I've been able to compile simple mex with OpenMP programs using gcc 4.4, but these did not have to link against anything except the math library. Also, if I compile with version gcc version 4.1.2 or 4.3.4 with or without the "-fopenmp" flags I get the same error.
In the end I do need version 4.4 because of certain OpenMP support that did not appear in prior versions.
Thanks in advance for the help.
--Andrew
Edits: (#KWATFORD)
So I tried the command with the statements outside the the quotes, and got the error:
-> 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.
I'm a bit confused about the suggestion to recompile with "-fPIC" because when I look at the gcc44 command I see the -fPIC as an option.
Are they saying to recompile the library with -fPIC?
I don't have the source for the library, if the suggestion is to recompile the library is there a workaround?
What does "relocation against local object" mean?
My continued thanks.
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.