- 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.
My CMakeLists.txt:
Full "CMAKE_World_COMPILER not set" error:
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?
- 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 asset(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?