ocaml-community / ocaml-linenoise

Self-contained OCaml bindings to linenoise, easy high level readline functionality in OCaml
http://ocaml-community.github.io/ocaml-linenoise/
51 stars 9 forks source link

Fix multiple definitions of linenoiseWasInterrupted #14

Closed tperami closed 4 years ago

tperami commented 4 years ago

The library relied on a non-standard behavior of GCC: When a global was defined multiple times, it is merged. This is control by option -fcommon. Starting from GCC 10, this not the default behavior anymore. The default is -fno-common that do not merge automatically global variables. This new behavior is compliant with the C standard. In this library the variable linenoiseWasInterrupted was defined twice: once in the header and once in a source file. I made the header line a declaration so that there is only a single definition in the source file. This library now compiles with GCC 10

tperami commented 4 years ago

Actually I was wrong, It seems that the -fcommon was the C standard compliant option and the new -fno-common in not, but is is the C++ way and is faster, that's why GCC 10 chose it as a default. Anyway, the code after this PR will work with both

c-cube commented 4 years ago

Thank you, that's a good catch. :)

tperami commented 4 years ago

I didn't really search for the bug. I just updated my system C compiler and then it failed to build