/usr/include Directory on WSL

Question:

I am using WSL on Windows and in the directory /usr/include I have a subdirectory called python3.8. As I understood the /usr/include includes the header files for C compilers.

I have installed python3.10 but it seems that python3.8 exists by default in WSL. Hence, I am having some conflicts with the directory python3.8 in /usr/include when I am trying to do python bindings with C++ using pybind11.

From the resulting error that I get when trying to import pybind11 header in C++ it is obvious that the program is looking for /usr/include/python3.10 (which does not exist) instead of /usr/include/python3.8.

As a solution I created a new directory called python3.10 in /usr/include and copied all the content inside /usr/include/python3.8. Thus, the problem disappeared and the program ran correctly but I am not quite sure that this is the best approach.

EDIT:

CMakeLists.txt file:

cmake_minimum_required(VERSION 3.4)
project(pybindproject)
add_subdirectory(pybind11)
pybind11_add_module(module_name main.cpp)

I have got pybind11 using: git clone https://github.com/pybind/pybind11.git

Asked By: Bianca

||

Answers:

Find where the python 3.10 was installed and find the include directory in the python 3.10 folder.

On WSL, just look at where you installed python, probably in your home directory if you installed from the tarball, then add to your environment C include path:

export CPATH='/home/../Python-3.10.6/Include':$CPATH

If you’re compiling with GCC from the command line, you can also manually specify an include path with the -I flag, like so:

g++ -I/whatever/path/to/python/include/dir foo.cpp
Answered By: Carter Canedy