CMake 3.12+ findPython3 to include Python.h

Viewed 584

I want to be able to create and run an executable file out of cpp class. The class is including the Python header

#include Python.h

Right now i have the Path to the Python lib linked in the lib directory in VC. However i want to be able to do it without that. In the CMake file, i found python using

find_package(Python3 REQUIRED COMPONENTS Interpreter Development)

What do i have to do now? I tried out

target_link_libraries(executable_name Python3::Module aswell as Python3::Python)

Both methods didn't work and i got the Error fatal error python.h no such file or directory. Thanks in advance.

2 Answers

You need to include the headers.

target_include_directories(executable_name PRIVATE ${PYTHON_INCLUDE_DIRS})

target_include_directories(executable_name PRIVATE ${Python3_INCLUDE_DIRS})

According to CMake FindPython3, note that the variables names start with Python3_ instead of PYTHON3.

Related