ModelicaStandardLibrary icon indicating copy to clipboard operation
ModelicaStandardLibrary copied to clipboard

Cannot compile library due to _BSD_SOURCE wrong usage

Open TeoGoddet opened this issue 1 year ago • 4 comments

Hello, I'm not a C expert, but I'm having problem compiling when I include open62541 lib (the amalgamated single file)

The error I have is

/mnt/c/Program Files/Dassault Systemes/B426_Cloud/win_b64/resources/Dymola/source/ModelicaInternal.c: In function ‘ModelicaInternal_fullPathName’:
/mnt/c/Program Files/Dassault Systemes/B426_Cloud/win_b64/resources/Dymola/source/ModelicaInternal.c:609:37: error: operator '||' has no left operand

line 609 looks like that in my dymola install : #if defined(_WIN32) || (_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || (_POSIX_VERSION >= 200112L)) The concerned line in the actual lib seems this one : https://github.com/modelica/ModelicaStandardLibrary/blob/bc5c458731def2ad5b128feb1b7e9a563b031a6a/Modelica/Resources/C-Sources/ModelicaInternal.c#L687

I think this occur because the _BSD_SOURCE define is empty because of this line in my lib : https://github.com/open62541/open62541/blob/6115a47125d7e6ccd77488b8572807171adb0602/tools/ua-tool/ua.c#L18

open62541 seems legit to define _BSD_SOURCE empty see https://ftp.gnu.org/old-gnu/Manuals/glibc-2.2.3/html_node/libc_13.html

I would suggest replacing _BSD_SOURCE by defined(_BSD_SOURCE) in ModelicaInternal.c I can open a MR is it seem the right fix

Note that there is three occurence of _BSD_SOURCE to fix

TeoGoddet avatar Feb 07 '24 14:02 TeoGoddet

defined(_BSD_SOURCE) resulted in error related "realpath" not existing I replaced _BSD_SOURCE by 0 and it compiled

TeoGoddet avatar Feb 07 '24 16:02 TeoGoddet

I can open a MR is it seem the right fix

Thanks for reporting. Your PR would be appreciated.

beutlich avatar Feb 08 '24 06:02 beutlich

@beutlich I can open a PR but i'm not confident enough in C and Modelica to be able to say that this fix is legitim I see you made this commit in 2020, are you able to confirm my intuition ?

TeoGoddet avatar Feb 08 '24 15:02 TeoGoddet

@beutlich I can open a PR but i'm not confident enough in C and Modelica to be able to say that this fix is legitim I see you made this commit in 2020, are you able to confirm my intuition ?

@TeoGoddet I created #4302. If you have a chance to test you can give a review comment there.

beutlich avatar Feb 08 '24 19:02 beutlich

#4302 is now merged.

@Esther-Devakirubai please back-port this to maint/v4.1.x

casella avatar Feb 11 '25 11:02 casella

please back-port this to maint/v4.1.x

Done by #4530.

beutlich avatar Feb 11 '25 17:02 beutlich

All set after #4530.

casella avatar Feb 24 '25 21:02 casella