3

When I create a new Flutter project in Android Studio (Android Studio Electric Eel | 2022.1.1), I build an APK and run it on the android emulator with no problem, but when I try to run it on linux I get this error:

CMake Error at /usr/share/cmake-3.25/Modules/CMakeDetermineCXXCompiler.cmake:48 (message):
    Could not find compiler set in environment variable CXX:
    clang++.
Call Stack (most recent call first):
    CMakeLists.txt:3 (project)
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
Exception: Unable to generate build files

My system (Pop!_OS 22.04 LTS) doesn't have that version of CMake installed, it has /usr/share/cmake-3.22 installed

And in Android Studio settings, under System Settings -> Android SDK -> SDK Tools, CMake 3.22.1 is installed

I am not able to figure out how to adjust the CMake version in Android Studio and what is the correct solution. Please any ideas?

5
  • CMake seems to complain about not being able to find clang++ compiler in the system. You could whether install clang++ or set CMAKE_CXX_COMPILER to an available compiler (e.g. g++). Commented Jan 21, 2023 at 22:04
  • Thanks for your answer. On my system these packages are already installed: clang and clang-14 Commented Jan 21, 2023 at 22:36
  • Can you execute clang++ from a command line? Commented Jan 21, 2023 at 22:41
  • I have been able to verify: clang test.cc ... OK g++ hello.cpp -o hello ...OK But: clang++ hello.cpp -o hello hello.cpp:1:9: fatal error: 'iostream' file not found I don't know if it is a correct way to run it in the terminal? When I type clang, the console displays these hints: clang clang++ clang++-14 clang-14 clang-cpp-14 Commented Jan 21, 2023 at 23:19
  • [✓] Linux toolchain - develop for Linux desktop • Ubuntu clang version 14.0.0-1ubuntu1 • cmake version 3.22.1 • ninja version 1.10.1 • pkg-config version 0.29.2 Commented Jan 21, 2023 at 23:44

1 Answer 1

5

SOLVED!

In the CMakeKists.txt file (in the /linux folder) I have added at the beginning (I think it has to be before the project(runner LANGUAGES CXX) line):

set(CMAKE_CXX_COMPILER "/usr/bin/g++")

Now it runs on linux with no problems.

EDIT (best solution):

sudo apt install lib32stdc++-12-dev
Sign up to request clarification or add additional context in comments.

5 Comments

It may be better to specify just g++, and not rely on where the binary lives, especially if you intend to run CMake on a different system.
Oh, and how can I do it?
set(CMAKE_CXX_COMPILER "g++") should work.
E: Unable to locate package lib32stdc++-12-dev
I'm using fedora and It didn't solve my problem either, unable to locate package and same error after set line adding

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.