mex function: multiple definition errors

7 ビュー (過去 30 日間)
Alexander Bähr
Alexander Bähr 2021 年 9 月 28 日
コメント済み: Alexander Bähr 2024 年 11 月 5 日
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
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
Alexander Bähr 2024 年 11 月 5 日
No solution yet, I continued without optimization

サインインしてコメントする。

回答 (1 件)

埃博拉酱
埃博拉酱 2024 年 11 月 5 日
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.

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by