modelica / ModelicaStandardLibrary

Free (standard conforming) library to model mechanical (1D/3D), electrical (analog, digital, machines), magnetic, thermal, fluid, control systems and hierarchical state machines. Also numerical functions and functions for strings, files and streams are included.
https://doc.modelica.org
BSD 3-Clause "New" or "Revised" License
452 stars 165 forks source link

Cannot compile library due to _BSD_SOURCE wrong usage #4301

Open TeoGoddet opened 5 months ago

TeoGoddet commented 5 months ago

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 commented 5 months ago

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

beutlich commented 5 months ago

I can open a MR is it seem the right fix

Thanks for reporting. Your PR would be appreciated.

TeoGoddet commented 5 months ago

@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 ?

beutlich commented 5 months ago

@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.