Search code examples
c++gccbuildocamlgcc-warning

How can I suppress g++ deprecation warnings in OCaml compilation when linking with C++ libraries?


When compiling an OCaml project which links against libraries requiring the C++ standard library (e.g. LLVM's OCaml bindings) using the -cc g++ argument to ocamlc with GCC >= 4.4 generates extremely verbose warning spew of the form:

warning: deprecated conversion from string constant to ‘char*’

How is it possible to remove these warnings?


Solution

  • The problem stems from ocamlc generating intermediate C code which triggers warnings when compiled in C++ mode by newer versions of GCC. But this generated code need not be compiled as C++. The only reason to pass -cc g++ for this common case of building against a wrapped C++ library is to ensure that the C++ standard library dependencies are built. The simpler solution, which avoids using the C++ front-end for compiling the ocamlc intermediate code, is simply:

    -cclib -lstdc++
    

    which forces linking the generated C code with libstdc++, while still compiling it in plain C mode.