CMake with vcpkg: CMAKE_C_COMPILER not set error on Ubuntu, but works fine on Windows

Hi, I am trying to set up a C project to be cross-platform with CMake and vcpkg. It works fine for me on windows, but on linux ubuntu sandbox it gives me this error when I run the following commands:

git clone -b master https://github.com/HallofFamer/{$myproject}.git
cd CLox
mkdir build
cmake -DCMAKE_TOOLCHAIN_FILE:STRING="/root/vcpkg/scripts/buildsystems/vcpkg.cmake" -S . -B ./build

Error message:

error: while detecting compiler information:
The log file content at "/root/vcpkg/buildtrees/detect_compiler/stdout-x64-linux.log" is:
-- Configuring x64-linux-rel
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:112 (message):
    Command failed: /root/vcpkg/downloads/tools/cmake-3.27.1-linux/cmake-3.27.1-linux-x86_64/bin/cmake /root/vcpkg/scripts/detect_compiler -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/root/vcpkg/packages/detect_compiler_x64-linux -DCMAKE_MAKE_PROGRAM=/root/vcpkg/downloads/tools/ninja/1.10.2-linux/ninja -DCMAKE_SYSTEM_NAME=Linux -DBUILD_SHARED_LIBS=OFF -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=/root/vcpkg/scripts/toolchains/linux.cmake -DVCPKG_TARGET_TRIPLET=x64-linux -DVCPKG_SET_CHARSET_FLAG=ON -DVCPKG_PLATFORM_TOOLSET=external -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON -DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=TRUE -DCMAKE_VERBOSE_MAKEFILE=ON -DVCPKG_APPLOCAL_DEPS=OFF -DCMAKE_TOOLCHAIN_FILE=/root/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON -DVCPKG_CXX_FLAGS= -DVCPKG_CXX_FLAGS_RELEASE= -DVCPKG_CXX_FLAGS_DEBUG= -DVCPKG_C_FLAGS= -DVCPKG_C_FLAGS_RELEASE= -DVCPKG_C_FLAGS_DEBUG= -DVCPKG_CRT_LINKAGE=dynamic -DVCPKG_LINKER_FLAGS= -DVCPKG_LINKER_FLAGS_RELEASE= -DVCPKG_LINKER_FLAGS_DEBUG= -DVCPKG_TARGET_ARCHITECTURE=x64 -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_BINDIR:STRING=bin -D_VCPKG_ROOT_DIR=/root/vcpkg -DZ_VCPKG_ROOT_DIR=/root/vcpkg -D_VCPKG_INSTALLED_DIR=/root/CLox/build/vcpkg_installed -DVCPKG_MANIFEST_INSTALL=OFF
    Working Directory: /root/vcpkg/buildtrees/detect_compiler/x64-linux-rel
    Error code: 1
    See logs for more information:
      /root/vcpkg/buildtrees/detect_compiler/config-x64-linux-rel-CMakeCache.txt.log
      /root/vcpkg/buildtrees/detect_compiler/config-x64-linux-rel-out.log
      /root/vcpkg/buildtrees/detect_compiler/config-x64-linux-rel-err.log

Call Stack (most recent call first):
  scripts/cmake/vcpkg_configure_cmake.cmake:344 (vcpkg_execute_required_process)
  scripts/detect_compiler/portfile.cmake:18 (vcpkg_configure_cmake)
  scripts/ports.cmake:147 (include)



error: vcpkg was unable to detect the active compiler's information. See above for the CMake failure output.
-- Running vcpkg install - failed
CMake Error at /root/vcpkg/scripts/buildsystems/vcpkg.cmake:895 (message):
  vcpkg install failed.  See logs for more information:
  /root/CLox/build/vcpkg-manifest-install.log
Call Stack (most recent call first):
  /usr/share/cmake-3.22/Modules/CMakeDetermineSystem.cmake:124 (include)
  CMakeLists.txt:5 (project)


CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

It seems that cmake/vcpkg isnt able to find the C compiler, though if I remove the vcpkg dependency it seems to work fine. Also the same command works perfectly on windows, is there a reason why it is having this issue on Linux?

Did you take a look in the log files mentioned in that error message? They usually contain details of why things failed.

Hi Craig,

I’ve checked the log files mentioned in the error message, they dont seem to provide any more information than what is already on the screen.

/root/vcpkg/buildtrees/detect_compiler/stdout-x64-linux.log:

-- Configuring x64-linux-rel
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:112 (message):
    Command failed: /root/vcpkg/downloads/tools/cmake-3.27.1-linux/cmake-3.27.1-linux-x86_64/bin/cmake /root/vcpkg/scripts/detect_compiler -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/root/vcpkg/packages/detect_compiler_x64-linux -DCMAKE_MAKE_PROGRAM=/root/vcpkg/downloads/tools/ninja/1.10.2-linux/ninja -DCMAKE_SYSTEM_NAME=Linux -DBUILD_SHARED_LIBS=OFF -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=/root/vcpkg/scripts/toolchains/linux.cmake -DVCPKG_TARGET_TRIPLET=x64-linux -DVCPKG_SET_CHARSET_FLAG=ON -DVCPKG_PLATFORM_TOOLSET=external -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON -DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=TRUE -DCMAKE_VERBOSE_MAKEFILE=ON -DVCPKG_APPLOCAL_DEPS=OFF -DCMAKE_TOOLCHAIN_FILE=/root/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON -DVCPKG_CXX_FLAGS= -DVCPKG_CXX_FLAGS_RELEASE= -DVCPKG_CXX_FLAGS_DEBUG= -DVCPKG_C_FLAGS= -DVCPKG_C_FLAGS_RELEASE= -DVCPKG_C_FLAGS_DEBUG= -DVCPKG_CRT_LINKAGE=dynamic -DVCPKG_LINKER_FLAGS= -DVCPKG_LINKER_FLAGS_RELEASE= -DVCPKG_LINKER_FLAGS_DEBUG= -DVCPKG_TARGET_ARCHITECTURE=x64 -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_BINDIR:STRING=bin -D_VCPKG_ROOT_DIR=/root/vcpkg -DZ_VCPKG_ROOT_DIR=/root/vcpkg -D_VCPKG_INSTALLED_DIR=/root/CLox/build/vcpkg_installed -DVCPKG_MANIFEST_INSTALL=OFF
    Working Directory: /root/vcpkg/buildtrees/detect_compiler/x64-linux-rel
    Error code: 1
    See logs for more information:
      /root/vcpkg/buildtrees/detect_compiler/config-x64-linux-rel-CMakeCache.txt.log
      /root/vcpkg/buildtrees/detect_compiler/config-x64-linux-rel-out.log
      /root/vcpkg/buildtrees/detect_compiler/config-x64-linux-rel-err.log

Call Stack (most recent call first):
  scripts/cmake/vcpkg_configure_cmake.cmake:344 (vcpkg_execute_required_process)
  scripts/detect_compiler/portfile.cmake:18 (vcpkg_configure_cmake)
  scripts/ports.cmake:147 (include)

/root/vcpkg/buildtrees/detect_compiler/config-x64-linux-rel-out.log:

-- The C compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- The CXX compiler identification is unknown
-- Configuring incomplete, errors occurred!

/root/vcpkg/buildtrees/detect_compiler/config-x64-linux-rel-err.log:

CMake Error at CMakeLists.txt:12 (enable_language):
  No CMAKE_CXX_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.

What C++ compiler are you expecting it to pick up? The output shows that it picks up /usr/bin/cc as the C compiler. Do you have a C++ compiler installed on your Linux machine?

Hi Craig.

I don’t have C++ compiler, the project is in pure C though and doesn’t require C++ anyway. But is a C++ compiler required for Cmake and vcpkg to work?

Also if I don’t use vcpkg, is it possible for Cmake to find library from installation path such as Curl on linux?

Edit: installed g++ on Ubuntu and still the same error, I have no idea how this works…

Yes vcpkg assumes that a useable C and C++ compiler exists. https://github.com/microsoft/vcpkg/blob/d5b03c125afee1d9cef38f4cfa77e229400fb48a/scripts/detect_compiler/CMakeLists.txt#L12