Ozballer31
Ozballer31

Reputation: 453

CMake skips standard precompiled headers

I'm new to C++, really trying to get familiar with CMake, but there's always something wrong.

I'm using CLion with Cygwin and G++11 package installed
My CMakeLists.txt file:

cmake_minimum_required(VERSION 3.20)
project(testing)

set(CMAKE_CXX_STANDARD 20)

if (NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif ()

set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

add_executable(testing main.cpp)

Clion says me that execution header is not found, but I could locate it in lib/ folder:

screenshot

Could somebody tell me what I'm doing wrong?

Upvotes: 1

Views: 166

Answers (1)

0x5453
0x5453

Reputation: 13599

Here are a few things I have tried when debugging similar problems:

  1. If in doubt, delete and re-create your build directories. CMake caches certain variables and can sometimes get into a weird state. A fresh directory will remove any uncertainty.
  2. CMake should print out what compiler it is using - Check that and make sure it's correct. For example, it could be finding an older version that does not have that header.
    1. In this case, the fix may be to put your desired compiler at the front of your PATH, or to force CMake to find the correct one via CMAKE_CXX_COMPILER.
  3. Build in verbose mode - you should be able to see what include paths are being used (-I, -isystem). Make sure that directory is in there.
    1. Alternatively, you can dump a compile_commands.json file that should contain the same information by setting CMAKE_EXPORT_COMPILE_COMMANDS=true
    2. Try using one of these build commands to build a single object in your Cygwin shell. If it works, it may indicate a problem with how your CLion is configured.

Upvotes: 1

Related Questions