Trying to use clangd with VSCodium, CMake_World_COMPILER not set

Joined
Oct 28, 2024
Messages
2
Reaction score
0
I am using VSCodium and, in the absence of the C/C++ microsoft extension, I have installed the "clangd" extension instead. I would like to get clangd to work. Currently, my C code does compile and run, but there is an error by clangd that says that <stdio.h> file is not found.

  • I have figured out that it's because compile_commands.json is required for clangd to work.
  • When I searched the clangd extension page, it said the easiest way to do it is with CMake
  • I create a CMakeLists.txt:
Code:
cmake_minimum_required(VERSION 3.10)

project(Hello World)

set(SOURCE_FILES helloworld.c)

add_executable(HelloWorld ${SOURCE_FILES})
  • Then I try to use "cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1". This didn't work and said that "CMAKE_World_COMPILER not set"
  • I tried adding set(CMAKE_C_COMPILER "C:/msys64/mingw64/bin/gcc.exe") to the CMakeLists.txt, as well as set(CMAKE_CXX_COMPILER "C:/msys64/mingw64/bin/g++.exe")
  • Trying to run the command again still gave me the same "CMAKE_World_COMPILER not set". I search this up online, which only gave me results for either CMAKE_C_COMPILER or CMAKE_CXX_COMPILER. But I have already set those!
  • I look online and found what seems to be a solution. I add set(CMAKE_EXPORT_COMPILE_COMMANDS ON) to the CMakeLists.txt. When I try to run "cmake ." in the terminal, the same "CMAKE_World_COMPILER not set" error appears.

My CMakeLists.txt:
Code:
cmake_minimum_required(VERSION 3.10)

set(CMAKE_C_COMPILER "C:/msys64/mingw64/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/msys64/mingw64/bin/g++.exe")

project(Hello World)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(SOURCE_FILES helloworld.c)

add_executable(HelloWorld ${SOURCE_FILES})

Full "CMAKE_World_COMPILER not set" error:
Code:
CMake Error at CMakeLists.txt:6 (project):
  Running

   'nmake' '-?'

  failed with:

   no such file or directory


CMake Error: CMAKE_World_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

TLDR: How do I make CMake work, and in turn, generate a compile_commands.json using CMake? Or should I skip over using CMake altogether and just make the compile_commands.json manually?
 
Joined
Oct 28, 2024
Messages
2
Reaction score
0
Found what I did wrong! It should be project(Hello_World), not project(Hello World). This fixes the CMAKE_World_COMPILER not set error. ("World" is not a valid programming language)

Also, appending -G "Ninja" fixed the nmake error
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,039
Messages
2,570,376
Members
47,032
Latest member
OdellBerg4

Latest Threads

Top