QtCreator does not recognize omp.h even though the program compiles and it can be run with g++
-
I am using QtCreator and CMake for C++ development. My CMakeLists.txt file is currently the following:
"""
cmake_minimum_required(VERSION 3.9)
project(my_project LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS_RELEASE "-O3")add_executable(my_project main.cpp)
find_package(OpenMP)
target_link_libraries(my_project PUBLIC OpenMP::OpenMP_CXX)"""
When I try to use OpenMPs functions such as the omp_get_num_threads(), I get the semantic issue:
"""
main.cpp:355:21: error: use of undeclared identifier 'omp_get_num_threads'
"""caused by the error that for some reason, the header file omp.h cannot be found:
"""
main.cpp:10:10: error: 'omp.h' file not found
"""However, I can run the program without any errors and the output does not seem exhibit undefined behavior. Compiling from the command line works as well e.g. by
"""
g++ main.cpp -fopenmp -std=c++20
"""What could be the root cause for this problem?
-
C Christian Ehrlicher moved this topic from Qt 6 on
-
Move
add_executable
line after youfind_package
. Not sure if it will help, but it might. -
Which version of Qt Creator are you using?
clangd
needs to be build with theopenmp
module enabled.You should check if you have
qtcreator/libexec/qtcreator/clang/lib/clang/17/include/omp.h
in your Qt Creator installation.The official https://download.qt.io/official_releases/qtcreator/13.0/ Qt Creator binaries all have right
clangd
andomp.h
header.