question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
eli-schwartzcommented, May 9, 2021

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

0reactions
bogen85commented, May 10, 2021

Alright, got it working with gcc/g++ and clang/clang++

I change my project to a 2 language project ['c', 'cpp']

I’m auto generating the cxx c source wrappers to a separate cxx source directory

for clang and gcc: I’ll always build both, only install the executable for the one compiled from c sources. For libraries I’ll always install both.

For msvc when I get to it I won’t build from c sources, only from cxx sources.

Read more comments on GitHub >

github_iconTop Results From Across the Web

meson.build:1:0: ERROR on Linux Mint 19.1 #137 - GitHub
build:1:0: ERROR: Compiler cc can not compile programs. I have all the necessary dependencies installed as per the readme.
Read more >
Anaconda : meson.build:1:0: ERROR: Compiler cc can not ...
build:1:0: ERROR: Compiler cc can not compile programs. Hi,. I would like to install libfprint. According to the documentation, I do this with ......
Read more >
Meson build system - change compiler to g++ - Stack Overflow
build:1:0: ERROR: Compiler c++ can not compile programs. It seems like meson is trying to compile with Microsoft compiler. I don't want it...
Read more >
Compiler Problems - Microsoft Q&A
I was using MSYS to do a meson build, and it started to compile fine (it ... MSYS started telling me 'compiler cc...
Read more >
61012 (graphene @1.10.2 +universal: meson.build:1:0: ERROR
Project name: graphene Project version: 1.10.2 meson.build:1:0: ERROR: Compiler ccache cc can not compile programs. A full log can be found at ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found