I am trying to build and run a Flutter application on Linux, but I am encountering issues with CMake. The application runs successfully on Google Chrome, but I'm having trouble getting it to work on Linux.
I have followed the steps provided in the Flutter documentation and made necessary modifications to the CMakeLists.txt
file as per the suggestions I received. Here are the steps I have taken:
I installed Flutter and ensured that it is set up correctly, as I can run the application on Google Chrome using
flutter run -d chrome
.I modified the
CMakeLists.txt
file in thelinux
directory of my Flutter project to set the C++ compiler and standard library explicitly. Here are the modifications I made:# Project-level configuration. cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) # Set the C++ compiler set(CMAKE_CXX_COMPILER "/usr/bin/clang++") # Static link the standard C++ library set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++") # Set C++17 standard set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") # Rest of the CMakeLists.txt content...
I also ran the following commands in the
linux
directory to build the project.cd linux rm -rf build mkdir build cd build cmake .. cmake --build .
However, during the build process, I encounter the following error:
CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message): The C++ compiler "/usr/bin/clang++" is not able to compile a simple test program. It fails with the following output: Change Dir: /home/farhan/App/flutter_application3/build/linux/x64/release/CMakeFiles/CMakeTmp Run Build Command(s):/usr/bin/ninja cmTC_47048 && [1/2] Building CXX object CMakeFiles/cmTC_47048.dir/testCXXCompiler.cxx.o [2/2] Linking CXX executable cmTC_47048 FAILED: cmTC_47048 : && /usr/bin/clang++ CMakeFiles/cmTC_47048.dir/testCXXCompiler.cxx.o -o cmTC_47048 && : /usr/bin/ld: cannot find -lstdc++: No such file or directory clang: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.
I am unable to resolve this issue, and I am not sure what's causing the problem. I have verified that I have the necessary dependencies installed on my Linux system.
Could anyone please guide me on how to properly set up CMake and resolve this issue so that I can build and run my Flutter application on Linux successfully?