Reputation: 33
I am trying to make a library written in C++ work in python, using pybind11.
The compilation and building of the source files works without errors, but the resulting files throw this error when installing with pip.
CMake Error at pybind11/tools/pybind11Tools.cmake:131 (add_library):
Cannot find source file:
../project/variables.cpp
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
Call Stack (most recent call first):
CMakeLists.txt:5 (pybind11_add_module)
CMake Error at pybind11/tools/pybind11Tools.cmake:131 (add_library):
No SOURCES given to target: project
Call Stack (most recent call first):
CMakeLists.txt:5 (pybind11_add_module)
I am following the cmake_example and I am sure that the file exists. In fact, if I delete the file the error occur when running
python setup.py sdist
The folder structure is like this:
C++ project root folder
|-- C++ Project source files
|-- pybind folder
|------pybind11 source folder
|----------pybind.cpp file
|------pybind11 CmakeLists.txt
|------pybind11 Manifest.in
This is the CMakeLists.txt used by pybind.
cmake_minimum_required(VERSION 2.8.12)
project(project)
add_subdirectory(pybind11)
pybind11_add_module(project
project/pybind.cpp
../project/variables.cpp
../project/instances.cpp
.
.
.
)
Both the C++ and the pybind source folders are included in the Manifest.in
file. Furthermore, ther is no error refering to project/pybind.cpp
file.
Also, this method of building the python module worked for me a couple months ago in the same project. I have tried downgradin setuptools, pybind11 and cmake but it does not work. I may be wrong, but I think the only chages I have made have been to add a couple C++ headers to the project and som functions in the pybind.cpp
file.
Upvotes: 2
Views: 14488
Reputation: 22023
You shouldn't use relative paths, because the location is given relative to some internal detail of CMake!
Use for instance:
${CMAKE_PROJECT_DIR}/project/variables.cpp
Or better, use the result of FILE
, as it populates these properly.
Even project/bind.cpp
should be relative, but you are lucky in the sense that CMake knows about that subfolder and figures it out. But don't do that, use FILE
to select them properly (you can be relative there).
FILE(GLOB PYBIND_SRC
project/pybind.cpp
../project/variables.cpp
../project/instances.cpp
)
pybind11_add_module(project
${PYBIND_SRC}
)
Upvotes: 5