# CMake with vcpkg: CMAKE\_C\_COMPILER not set error on Ubuntu, but works fine on Windows

**URL:** https://discourse.cmake.org/t/cmake-with-vcpkg-cmake-c-compiler-not-set-error-on-ubuntu-but-works-fine-on-windows/8791
**Category:** Usage
**Tags:** os:linux
**Created:** [August 20, 2023, 6:28pm UTC](https://discourse.cmake.org/t/cmake-with-vcpkg-cmake-c-compiler-not-set-error-on-ubuntu-but-works-fine-on-windows/8791 "2023-08-20T18:28:47Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![HallofFamer](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/f475e1/32.png) [@HallofFamer](https://discourse.cmake.org/u/HallofFamer)
#### Post date: [August 20, 2023, 6:28pm UTC](https://discourse.cmake.org/t/cmake-with-vcpkg-cmake-c-compiler-not-set-error-on-ubuntu-but-works-fine-on-windows/8791/1 "2023-08-20T18:28:47Z")

</div>

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:

```auto
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:

```auto
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?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [August 20, 2023, 11:38pm UTC](https://discourse.cmake.org/t/cmake-with-vcpkg-cmake-c-compiler-not-set-error-on-ubuntu-but-works-fine-on-windows/8791/2 "2023-08-20T23:38:03Z")

</div>

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

---

<div class="post-metadata">

### Author: ![HallofFamer](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/f475e1/32.png) [@HallofFamer](https://discourse.cmake.org/u/HallofFamer)
#### Post date: [August 21, 2023, 1:28am UTC](https://discourse.cmake.org/t/cmake-with-vcpkg-cmake-c-compiler-not-set-error-on-ubuntu-but-works-fine-on-windows/8791/3 "2023-08-21T01:28:56Z")

</div>

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:

```auto
-- 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:

```auto
-- 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:

```auto
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.

```

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [August 21, 2023, 9:00pm UTC](https://discourse.cmake.org/t/cmake-with-vcpkg-cmake-c-compiler-not-set-error-on-ubuntu-but-works-fine-on-windows/8791/4 "2023-08-21T21:00:55Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![HallofFamer](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/f475e1/32.png) [@HallofFamer](https://discourse.cmake.org/u/HallofFamer)
#### Post date: [August 21, 2023, 11:20pm UTC](https://discourse.cmake.org/t/cmake-with-vcpkg-cmake-c-compiler-not-set-error-on-ubuntu-but-works-fine-on-windows/8791/5 "2023-08-21T23:20:11Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![Neumann-A](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neumann-a/32/1647_2.png) [@Neumann-A](https://discourse.cmake.org/u/Neumann-A)
#### Post date: [August 22, 2023, 11:52am UTC](https://discourse.cmake.org/t/cmake-with-vcpkg-cmake-c-compiler-not-set-error-on-ubuntu-but-works-fine-on-windows/8791/6 "2023-08-22T11:52:29Z")

</div>

Yes vcpkg assumes that a useable C and C++ compiler exists. [https://github.com/microsoft/vcpkg/blob/d5b03c125afee1d9cef38f4cfa77e229400fb48a/scripts/detect\_compiler/CMakeLists.txt#L12](https://github.com/microsoft/vcpkg/blob/d5b03c125afee1d9cef38f4cfa77e229400fb48a/scripts/detect_compiler/CMakeLists.txt#L12)
