meson: meson.build:1:0: ERROR: Compiler g++ can not compile programs.

Describe the bug Meson prohibits the use a c++ compiler for C, even when an existing code base compiles and runs fine for each. CC=g++ and CC=clang++ both fail. (CC=gcc and CC=clang both succeed)

The issue is that my project uses nested functions. These are supported on clang and gcc and c++ (I use macros to define them based on compiler).

Building on Linux/BSD/etc, no problem, clang and gcc are generally available.

On windows clang or gcc might not be available.

msvc C does not support nested functions (AFAIK), but msvc c++ does (recent standards, C++ lambdas).

So, when not using meson to build, the code can be compiled on more platforms, but with meson, it is limited to those with gcc and clang.

Yes, those are available on windows… but if msvc is available, it would be easier to use it’s c++ compiler.

So without meson as the build system, clang or gcc would not be required on windows if msvc is available.

With meson as the build system, clang or gcc would be required on windows even if msvc is available.

sanitycheckc.c is valid C, but it is not valid C++, so the sanity check fails. c int main(void) { int class=0; return class; }

Since the sanity check fails, meson gives up

To Reproduce my meson.build: project( 'sample', 'c', version : '0.0.1', default_options : ['warning_level=3'], license: 'MIT', )

Expected behavior

Meson to accept a C++ compiler as a C compiler (does not need to be via CC=, could be some other mechanism), as the needed options to force c++ for .c ‘-xc++’ (for clang++ can g++) are added later. (And when just using make, the code base builds and runs fine with gcc, clang, g++, and clang++)

C++ is a superset of C, and can compile most C code that is not invalid C++ code. Obviously if one is to have a project work when compiled with C or C++, they must be aware of the intersection of the two languages, and know how to deal with any differences.

system parameters

  • Is this a cross build or just a plain native build (for the same computer)? Answer: Native

  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.) Answer: Arch Linux $ cat /etc/os-release NAME="Arch Linux" PRETTY_NAME="Arch Linux" ID=arch BUILD_ID=rolling ANSI_COLOR="38;2;23;147;209" HOME_URL="https://www.archlinux.org/" DOCUMENTATION_URL="https://wiki.archlinux.org/" SUPPORT_URL="https://bbs.archlinux.org/" BUG_REPORT_URL="https://bugs.archlinux.org/" LOGO=archlinux

  • what Python version are you using e.g. 3.8.0 $ python --version Python 3.9.4

  • what meson --version $ meson --version 0.58.0

  • what ninja --version if it’s a Ninja build $ ninja --version 1.10.2

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

I guess in theory we could add a core option e.g. “compile_c_as_cpp”.