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
jiancong
2024년 11월 5일
I have the same questiones.Did your solve it?
Abhishek Kumar Singh
2024년 11월 5일
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.
Alexander Bähr
2024년 11월 5일
답변 (1개)
埃博拉酱
2024년 11월 5일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!