Hello!
So I have some application called myapp (for example), which needs clang of version 14 or higher for building, and following important part of snapcraft.yaml:
base: core20
confinement: devmode
parts:
myapp:
plugin: make
source-type: local
source: ./myapp/
build-packages:
- clang
- git
- python
- make
- cmake
- ninja-build
override-build: |
export CC=clang-14
export CXX=clang++-14
mkdir build
cd build
cmake ..
ninja
But when I try to build it with:
sudo snapcraft --use-lxd
It returns me on the override-build stage:
CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineCCompiler.cmake:49 (message):
Could not find compiler set in environment variable CC:
clang-14.
Call Stack (most recent call first):
CMakeLists.txt:29 (project)
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
What am I doing wrong? Maybe there is another way to set 14 version in snap? When I try do it all myself locally without snap (with export CC and CXX commands), everything builds correctly.
Hmm, I asked my question badly. It’s true that -clang-12 will be newer than just -clang. But that doesn’t seem to be my problem. For example, If I delete export commands and leave snapcraft.yaml as:
base: core20
confinement: devmode
parts:
myapp:
plugin: make
source-type: local
source: ./myapp/
build-packages:
- clang-12
- git
- python
- make
- cmake
- ninja-build
override-build: |
mkdir build
cd build
cmake ..
ninja
It will return:
CMake Error at cmake/tools.cmake:17 (message):
GCC version must be at least 11. For example, if GCC 11 is available under
gcc-11, g++-11 names, do the following: export CC=gcc-11 CXX=g++-11; rm -rf
CMakeCache.txt CMakeFiles; and re run cmake or ./release.
Call Stack (most recent call first):
CMakeLists.txt:46 (include)
If I understand it right (maybe I’m not right), the problem is not in the version of clang, but in the version of C++, which I need somehow to enable to be C++11 or C++14 or higher. And I don’t know how to do exactly that in Snapcraft. I tried to do it using export, but then I got error as in the first message.
Your second error was that you were not installing gcc nor g++ and not setting CC (and CXX). So cmake couldn’t find a compiler (IIRC it tries gcc by default).
Your first error was that you were setting CC (and CXX) to the non-existent clang-14. So cmake couldn’t find the compiler you specified.
If you only need “c++11 or c++14”, then the simplest solution would be to install g++. Then cmake will find it. Or you could use clang, but set CC=clang and CXX=clang++.
If you specifically want to use clang-12, then you need to set CC and CXX accordingly.