mex function: multiple definition errors

I have a c mex function compiled from a couple of source files. Matlab version is R2018b for windows 64, compiler is "Matlab support for mingw64-gcc compiler" version 18.2.0. (GCC 6.3.0?)
Everything is fine when I use the -g option, disabling optimization. When I use -g and -O oder none of them, then lots of errors occur during linking like:
C:\Users\[..]\AppData\Local\Temp\mex_15931488277591_20624\CON_SCALC.obj:CON_SCALC.c:(.text+0x200):
multiple definition of `fabsf'
C:\Users\[..]\AppData\Local\Temp\mex_15931488277591_20624\cs_firmware.obj:cs_firmware.c:(.text+0x4e0):
first defined here
C:\Users\[..]\AppData\Local\Temp\mex_15931488277591_20624\CON_SCALC.obj:CON_SCALC.c:(.text+0x210):
multiple definition of `fabsl'
C:\Users\[..]\AppData\Local\Temp\mex_15931488277591_20624\cs_firmware.obj:cs_firmware.c:(.text+0x4f0):
first defined here
C:\Users\[..]\AppData\Local\Temp\mex_15931488277591_20624\CON_SCALC.obj:CON_SCALC.c:(.text+0x220):
multiple definition of `fabs'
C:\Users\[..]\AppData\Local\Temp\mex_15931488277591_20624\cs_firmware.obj:cs_firmware.c:(.text+0x500):
first defined here
C:\Users\[..]\AppData\Local\Temp\mex_15931488277591_20624\CON_SCALC.obj:CON_SCALC.c:(.text+0x230):
multiple definition of `__fpclassifyl'
C:\Users\[..]\AppData\Local\Temp\mex_15931488277591_20624\cs_firmware.obj:cs_firmware.c:(.text+0x510):
first defined here
C:\Users\[..]\AppData\Local\Temp\mex_15931488277591_20624\CON_SCALC.obj:CON_SCALC.c:(.text+0x2a0):
multiple definition of `__fpclassify'
C:\Users\[..]\AppData\Local\Temp\mex_15931488277591_20624\cs_firmware.obj:cs_firmware.c:(.text+0x580):
first defined here
As far as I understand, these are C library functions either from math.h or implicitly used by the one or another module. They are somehow included in each object and regarded as duplicates.
How can I fix this?
Thanks

3 Comments

I have the same questiones.Did your solve it?
Please check your C code for multiple definitions. Adding in an “ifndef” to the header file would should remove those errors however that function or object may also be defined as something else in another file.
Also, ensure that your GCC and associated libraries are up to date. Sometimes, older versions might have bugs or issues that have been resolved in newer releases.
If it doesn't work, try this in a latest version with fresh MEX installation and recheck the configuration.
No solution yet, I continued without optimization

Sign in to comment.

Answers (1)

Enabling optimization means that the definition of some built-in macros will change, resulting in different compilation conditions for some conditions, which is difficult to summarize in a word. I'd suggest you check if some #if blocks have optimization-related conditions.
A better approach is to develop with a mature IDE such as Visual Studio.

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Release

R2018b

Asked:

on 28 Sep 2021

Commented:

on 5 Nov 2024

Community Treasure Hunt

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

Start Hunting!