Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing -std=c++11 when compiling C++ files #10886

Closed
kit-ty-kate opened this issue Sep 5, 2024 · 7 comments · Fixed by #10962
Closed

Missing -std=c++11 when compiling C++ files #10886

kit-ty-kate opened this issue Sep 5, 2024 · 7 comments · Fixed by #10962

Comments

@kit-ty-kate
Copy link
Member

See ocaml/ocaml#13422
OCaml 5.3 requires -std=c++11 to be passed when C++ is used.
From what i understand Dune 3 passes +x c++ automatically to the C compiler so it should probably also add this option too.

@MisterDA
Copy link
Contributor

MisterDA commented Sep 5, 2024

To be pendantic I suggest that Dune checks that the C++ compiler it uses defaults at least to C++11. This can be checked with cc-style compilers by:

$ cc -dM -E -x c++ - < /dev/null | grep __cplusplus
#define __cplusplus 199711L
$ cc --version
Apple clang version 15.0.0 (clang-1500.3.9.4)
$ /opt/homebrew/Cellar/llvm/18.1.8/bin/clang -dM -E -x c++ - < /dev/null | grep __cplusplus
#define __cplusplus 201703L
$ /opt/homebrew/bin/gcc-14 -dM -E -x c++ - < /dev/null | grep __cplusplus
#define __cplusplus 201703L

You see here that Apple clang 15 defaults to C++98, but clang and gcc installed via Homebrew default to C++17.

MSVC defaults to C++14, so that's fine.

@MisterDA
Copy link
Contributor

Note that clang-16 shipped with the new macOS 15.0 Sequoia still defaults to C++98.

@rgrinberg
Copy link
Member

@MisterDA do you want to send a PR?

@MisterDA
Copy link
Contributor

I don't think that passing a specific version of C++ is the way to go… I would rather have Dune detect the version of C++ the C++ compiler defaults to, if there are C++ stubs, and pass -std=c++11 if it default to a version older than C++11. I'm not sure where that could go in Dune.

@kit-ty-kate
Copy link
Member Author

I don't think that passing a specific version of C++ is the way to go… I would rather have Dune detect the version of C++ the C++ compiler defaults to, if there are C++ stubs, and pass -std=c++11 if it default to a version older than C++11.

If this is to avoid issues with having the option overwrite the default or a user-given -std=[...] i don't think these are a problem at all:

  • the default would be overwritten only for OCaml 5.3 so it should be detected early when users upgrade
  • additional -std=[...] given to a command override the previous definition so there is no problem there either

@MisterDA
Copy link
Contributor

Makes sense.

the default would be overwritten only for OCaml 5.3 so it should be detected early when users upgrade

We could also default to C++11 for all OCaml 5 versions.

@kit-ty-kate
Copy link
Member Author

I opened #10962 to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants