mex function: multiple definition errors
24 次查看(过去 30 天)
显示 更早的评论
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 个评论
Abhishek Kumar Singh
2024-11-5,5:56
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.
回答(1 个)
埃博拉酱
2024-11-5,7:56
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!