Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified cmake example cannot find pybind11.h #1206

Closed
molpopgen opened this issue Dec 6, 2017 · 2 comments · Fixed by #2433
Closed

modified cmake example cannot find pybind11.h #1206

molpopgen opened this issue Dec 6, 2017 · 2 comments · Fixed by #2433
Assignees

Comments

@molpopgen
Copy link

Issue description

Trying to use find_package in the cmake_example results in failure to find pybind11 headers when pybind11 is in /usr/local

The issue appears to be that the include path is set to /usr/local/include rather than /usr/local/include/python3.5

Reproducible example code

This is on Ubuntu 16.04, with pybind11 2.2.1 installed via pip3.

pybind11 does know how to get the correct include paths:

python3 -c "import pybind11;print(pybind11.__file__)"
/usr/local/lib/python3.5/dist-packages/pybind11/__init__.py
python3 -m pybind11 --includes
-I/usr/include/python3.5m -I/usr/local/include/python3.5 -I/home/kevin/.local/include/python3.5m

Below is how I found the issue:

I cloned the cmake_example (non-recursively) and modified CMakeLists to read:

cmake_minimum_required(VERSION 2.8.12)
project(cmake_example)

find_package(pybind11)
message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
pybind11_add_module(cmake_example src/main.cpp)

The output of cmake . is below, and you can see that the INCLUDE_DIRS will cause a problem:

-- The C compiler identification is GNU 5.4.1
-- The CXX compiler identification is GNU 5.4.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /usr/bin/python3.5 (found version "3.5.2") 
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.5m.so
-- Performing Test HAS_CPP14_FLAG
-- Performing Test HAS_CPP14_FLAG - Success
-- Performing Test HAS_CPP11_FLAG
-- Performing Test HAS_CPP11_FLAG - Success
-- Found pybind11 v2.1.dev0: /usr/local/include;/usr/include/python3.5m
-- Performing Test HAS_FLTO
-- Performing Test HAS_FLTO - Success
-- LTO enabled
-- Configuring done
-- Generating done

The output of make VERBOSE=1 is:

[ 50%] Building CXX object CMakeFiles/cmake_example.dir/src/main.cpp.o
/usr/bin/c++   -Dcmake_example_EXPORTS -I/usr/local/include -I/usr/include/python3.5m  -fPIC   -std=c++14 -flto -fno-fat-lto-objects -o CMakeFiles/cmake_example.dir/src/main.cpp.o -c /home/kevin/src/cmake_example/src/main.cpp
/home/kevin/src/cmake_example/src/main.cpp:1:31: fatal error: pybind11/pybind11.h: No such file or directory
@molpopgen
Copy link
Author

I've looked into this further and I seem to have solved the problem:

  1. It appears that my pybind11-supplied cmake files were out of date.
  2. Installing pybind11 via pip does not install the pybind11/tools files.
  3. I was able to get things working by installing pybind11 via "cmake . && make install"

In other words, I somehow had out of date files in /usr/local/share/cmake/pybind11. Upgrading pybind11 via sudo pip3 install --upgrade pybind11 did not upgrade those files.

It point 2 above an issue that needs fixing? I have confirmed this behavior on OS X and Ubuntu Linux. The cmake files are, however, installed, via conda install pybind11.

@molpopgen
Copy link
Author

I see now that this came up in #698. It seems like there is a documentation issue here. In order to have both the cmake files installed and the ability to say python -m pybind11 --includes, one has to both make install and pip install . the package. Is that the current state of things?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants