Giter Site home page Giter Site logo

cmake_cpp_pybind11_tutorial's Introduction

Setting up a C++/Python project with pybind11 and CMake

This tutorial shows how to set up a pybind11 project with CMake for wrapping a C++ library into Python.

The final result will be:

  • A C++ project you can build independent of pybind11.
  • A Python library generated from wrapping the C++ code.
  • Both using CMake.

drawing

Image source.

Create a C++ project

We will use the outer (current) working directory to build python, and an inner directory called cpp to build the C++ code. First make a C++ directory.

mkdir cpp
cd cpp

Next, we will initialize a C++ project. Two ways (of many more) are:

  1. Using VS Code. Install the CMake Tools extension. Then, bring up the command pallette and select CMake: Quick start. Follow the prompts and enter a name - I chose automobile. When prompted for library or executable, choose library. Your directory should now look like this:

    cpp/build/
    cpp/automobile.cpp
    cpp/CMakeLists.txt
    

    We will separate the source and header files - this is always good practice. In the cpp directory, make two new directories:

    cd cpp
    mkdir include
    mkdir src
    

    and move the source file:

    mv automobile.cpp src/
    

    In the include directory, we would like to have a single header to import. This way, we could later simply #include <automobile>. We can organize it as follows:

    cd cpp/include
    mkdir automobile_bits
    touch automobile
    

    Finally, let us create a header file in the cpp/include/automobile_bits directory:

    cd cpp/include/automobile_bits
    touch motorcycle.hpp
    

    The final directory structure should now look like this:

    cpp/build
    cpp/CMakeLists.txt
    cpp/include/automobile
    cpp/include/automobile_bits/motorcycle.hpp
    cpp/src/motorcycle.cpp
    
  2. Manually create the files and directories, such that the final structure is:

    cpp/build
    cpp/CMakeLists.txt
    cpp/include/automobile
    cpp/include/automobile_bits/motorcycle.hpp
    cpp/src/motorcycle.cpp
    

We will need to edit the current CMakeLists.txt such that it can find the header and source files. I edited mine to read as follows:

cmake_minimum_required(VERSION 3.1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

project(automobile VERSION 0.1.0)

# Include dir
include_directories(/usr/local/include)

# Src
AUX_SOURCE_DIRECTORY(src SRC_FILES)

# Headers
set(PROJECT_SOURCE_DIR "src")
set(PROJECT_INCLUDE_DIR "include/automobile_bits")

# Source files
set(SOURCE_FILES
    ${PROJECT_INCLUDE_DIR}/motorcycle.hpp
    ${PROJECT_SOURCE_DIR}/motorcycle.cpp
)

# Set up such that XCode organizes the files correctly
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE_FILES})

# Add library
add_library(automobile SHARED ${SOURCE_FILES})

# Include directories
target_include_directories(automobile PRIVATE include/automobile_bits)

# Install
install(TARGETS automobile DESTINATION lib)

# Install the headers
install(FILES include/automobile DESTINATION include)

# Create base directory
install(DIRECTORY include/automobile_bits DESTINATION include)

Let's also give the motorcycle.hpp and motorcycle.cpp files some reasonable content. For the header:

#include <string>

#ifndef CAR_H
#define CAR_H

namespace vehicles {

class Motorcycle {

private:

    /// Name
    std::string _name;

public:

    /// Constructor
    Motorcycle(std::string name);

    /// Get motorcycle name
    /// @return Motorcycle name
    std::string get_name() const;

    /// Drive the motorcycle
    void ride() const;
};

}

#endif

and the source:

#include "../include/automobile_bits/motorcycle.hpp"

#include <iostream>

namespace vehicles {

Motorcycle::Motorcycle(std::string name) {
    _name = name;
}

std::string Motorcycle::get_name() const {
    return _name;
}

void Motorcycle::ride() const {
    std::cout << "Zoom Zoom" << std::endl;
}

}

Yes! I know they're dumb. Note that we introduced a namespace vehicles - this is always a good idea.

We also need to have the header file find the actual library. Edit the include/automobile file to read:

#ifndef AUTOMOBILE_LIBRARY_H
#define AUTOMOBILE_LIBRARY_H

#include "automobile_bits/motorcycle.hpp"

#endif

We can now already build the library:

  1. Using the command line:

    cd cpp/build
    cmake ..
    make
    make install
    
  2. Using your favorite IDE, e.g. XCode:

    cd cpp/build
    cmake .. -GXcode
    

    should generate automobile.xcodeproject in the build directory.

Either way, you should get the library to build and install.

Testing the C++ library

Before we go on to wrapping the library into Python, let's create a test for the C++ library (not a real test, just somewhere for us to mess around!).

Create a new directory in cpp:

cd cpp
mkdir tests

Here we will again set up a CMake project for our test. Make the directory structure look as follows:

cpp/tests/CMakeLists.txt
cpp/tests/src/test_cpp.cpp

Edit the test_cpp.cpp file to read:

#include <automobile>

#include <iostream>

int main() {

    vehicles::Motorcycle c("Yamaha");

    std::cout << "Made a motorcycle called: " << c.get_name() << std::endl;

    c.ride();

    return 0;
}

and edit the CMakeLists.txt file:

cmake_minimum_required(VERSION 3.1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

project(test_cpp)

include_directories(/usr/local/include)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/../bin)

find_library(AUTOMOBILE_LIB automobile HINTS /usr/local/lib/)

add_executable(test_cpp src/test_cpp.cpp)

target_link_libraries(test_cpp PUBLIC ${AUTOMOBILE_LIB})

Make and run that bad boy using XCode as before, or from the command line:

mkdir build
cd build
cmake ..
make
cd ../bin
./test_cpp

Note that the binary will be in the bin directory. The output should be:

Made a motorcycle called: Yamaha
Zoom Zoom on road: mullholland

Setting up the Python wrapper

Finally, let's get to wrapping the library into a Python. We're moving up a directory! In the main directory, let's make a new directory called python. It will hold all the glue code:

mkdir python

We also need a CMakeLists.txt file, with contents:

cmake_minimum_required(VERSION 3.1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_CXX_FLAGS "-O3")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

project(automobile)

include_directories("${CMAKE_SOURCE_DIR}/cpp/include/automobile_bits")
include_directories("${CMAKE_SOURCE_DIR}/python")

file (GLOB SOURCE_FILES "cpp/src/*.cpp")
file (GLOB HEADER_FILES "cpp/include/automobile_bits/*.hpp")
file (GLOB PYTHON_FILES "python/*.cpp" "python/*.hpp")

# Set up such that XCode organizes the files
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE_FILES} ${HEADER_FILES} ${PYTHON_FILES} )

find_package(pybind11 REQUIRED)

If pybind11 hasn't been installed in the system (e.g.: conda install -c conda-forge pybind11), you can use the pybind11.cmake file to fetch the package (see CMakeLists.txt as an example).

pybind11_add_module(automobile 
	${SOURCE_FILES}
	${HEADER_FILES}
	${PYTHON_FILES}
)

target_link_libraries(automobile PUBLIC)

install(TARGETS automobile
  COMPONENT python
  LIBRARY DESTINATION "${PYTHON_LIBRARY_DIR}"
  )

You should be ready to build your Python library! Try:

mkdir build
cd build
cmake .. -DPYTHON_LIBRARY_DIR="/path/to/site-packages" -DPYTHON_EXECUTABLE="/path/to/executable/python3"
make
make install

As usual, you could also generate code using a generator for your favorite IDE, e.g. by adding -GXcode to the cmake command. My paths were:

DPYTHON_LIBRARY_DIR="/Users/USERNAME/opt/anaconda3/lib/python3.7/site-packages"
DPYTHON_EXECUTABLE="/Users/USERNAME/opt/anaconda3/bin/python3"

Note that if you are lazy like me, you can try to add for testing:

set(PYTHON_LIBRARY_DIR "/Users/USERNAME/opt/anaconda3/lib/python3.7/site-packages")
set(PYTHON_EXECUTABLE "/Users/USERNAME/opt/anaconda3/bin/python3")

in your CMakeLists.txt - obviously not a good trick for production!

Fire up python (make sure it's the same as you specified in PYTHON_EXECUTABLE above) and try:

>>> import automobile
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_automobile)

You got a nice fat error, but that's OK! We didn't write the glue code yet, but at least your CMake is working and Python can find your library.

Wrapping the library into Python

Now for the actual logic of wrapping the C++ code into Python. It will take place in the python directory. First create a file which will define the "module export function" that python was complaning about in the last part:

touch python/automobile.cpp

Give it the following content:

#include <pybind11/pybind11.h>

namespace py = pybind11;

void init_motorcycle(py::module &);

namespace mcl {

PYBIND11_MODULE(automobile, m) {
    // Optional docstring
    m.doc() = "Automobile library";
    
    init_motorcycle(m);
}
}

Next, we will define the init_motorcycle method that was declared. We will do this in a separate file:

touch python/motorcycle.cpp

Edit it to read:

#include "../cpp/include/automobile_bits/motorcycle.hpp"

#include <pybind11/stl.h>

#include <pybind11/pybind11.h>
namespace py = pybind11;

void init_motorcycle(py::module &m) {
    
    py::class_<vehicles::Motorcycle>(m, "Motorcycle")
    .def(py::init<std::string>(), py::arg("name"))
    .def("get_name",
         py::overload_cast<>( &vehicles::Motorcycle::get_name, py::const_))
    .def("ride",
         py::overload_cast<std::string>( &vehicles::Motorcycle::ride, py::const_),
         py::arg("road"));
}

I always find the code itself to be the best explanation, but some pointers:

  • py::class_<vehicles::Motorcycle>(m, "Motorcycle") defines the class. The "Motorcycle" defines the name of the class in Python - you could change it if you want! Notice also the appearance of the namespace.
  • .def(py::init<std::string>(), py::arg("name")) defines the constructor. The py::arg("name") allows you to use named arguments in Python.
  • .def("get_name", py::overload_cast<>( &vehicles::Motorcycle::get_name, py::const_)) wraps the get_name method. Note how the const declaration is wrapped.
  • .def("ride", py::overload_cast<std::string>( &vehicles::Motorcycle::ride, py::const_), py::arg("road")); wraps the ride method. The arguments to the method are declared in py::overload_cast<std::string> (separated by commas if multiple), and can again be named using py::arg("road"). Also note the semicolon at the end - often forgotten, but this should be proper C++ code.

You can now test your library. Run make and make install again to rebuild and install the library.

Fire up python and try it:

import automobile
c = automobile.Motorcycle("Yamaha")
print("Made a motorcycle called: %s" % c.get_name())
c.ride("mullholland")

should give the same output as before:

Made a motorcycle called: Yamaha
Zoom Zoom on road: mullholland

You could make another test script with those contents, located in a directory tests/test.py.

Conclusion

That's it for this tutorial. The nice part about this setup is that you can build your C++ project in peace from the cpp directory, and then at the end in the outer layer worry about wrapping it into Python.

You can read about more advanced pybindy11 features in another tutorial here.

cmake_cpp_pybind11_tutorial's People

Contributors

fornof avatar smrfeld avatar tengomucho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cmake_cpp_pybind11_tutorial's Issues

Building with make

I am learning this for the first time, hence my use of this tutorial, so this is likely a result of my inexperience. But maybe someone else has the same issue..

I am running cmake 3.19.7 and GNU Make 3.81 on macOS 10.14.6.

When I've run cmake .. from the cpp/build directory i get the output

-- Configuring done
-- Generating done
-- Build files have been written to: /Users/(...)/pybind_tutorial/cpp/build

Then, when i run make, i get make: *** No targets specified and no makefile found. Stop.
Running make install returns make: *** No rule to make target 'install'. Stop..

My project structure is as described in the tutorial:

cpp/build
cpp/CMakeLists.txt
cpp/include/automobile
cpp/include/automobile_bits/motorcycle.hpp
cpp/src/motorcycle.cpp

After running the cmake .. command, the cpp/build directory holds the files

build.ninja
cmake_install.cmake
CMakeCache.txt
compile_commands.json
CPackConfig.cmake
CPackSourceConfig.cmake
CTestTestfile.cmake
DartConfiguration.tcl

The cpp/build/CMakeFiles directory contains

cmake.check_cache
CMakeOutput.log
rules.ninja
TargetDirectories.txt
automobile.dir/src (empty directory)
3.19.7 (what looks like standard version-specific cmake files)

As said, I feel like this is a product of my inexperience, but any help getting this to work would be greatly appreciated.

Edit:
Following this tutorial worked, although i can't seem to understand why that worked and not your tutorial, I'm guessing it has something to do with the different CMakeLists.txt files? I prefer written tutorials to videos, but that video is the only thing I've come across in over a day that ended up working for me.

use pybind11 package in VSCODE

Hello, @smrfeld ,Thanks for sharing this pybind11-cmake tutorial! Actually, This is not a issue but a request.

I am a beginner of pybind11 and this project helps me a lot. However, I am wondering how to let VSCODE automatically highlight pybind package like ordinary python pacakge, as well as automatically complete args and function names. Should I add py.in files?

suggestion

In the step "Testing the C++ library", the current version of your code throws an error because "test" is a reserved word while running make on Ubuntu. The issue is resolved after I changed the test names to tests. You may like to update naming with a safer word.

Build fails with multiple errors

The configure step runs without error. The build has so many errors, and such odd ones, that my first guess is that I need to update something. But what?

Python 3.11, Visual Studio 17.6.3.

Would you like me to try the latest pybind11.h before you look into this?


C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial>cmake --build build
MSBuild version 17.6.3+07e294721 for .NET Framework

Checking Build System
Building Custom Rule C:/Users/beryl/source/repos/cmake_cpp_pybind11_tutorial/CMakeLists.txt
cl : command line warning D9002: ignoring unknown option '-O3' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutoria
l\build\automobile.vcxproj]
motorcycle.cpp
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\ostream(774,1): warning C4530
: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc [C:\Users\beryl\source\repos\cmake_cp
p_pybind11_tutorial\build\automobile.vcxproj]
C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\cpp\src\motorcycle.cpp(16,15): message : see reference to funct
ion template instantiation 'std::basic_ostream<char,std::char_traits> &std::operator <<<std::char_traits>(s
td::basic_ostream<char,std::char_traits> &,const char *)' being compiled [C:\Users\beryl\source\repos\cmake_cpp_p
ybind11_tutorial\build\automobile.vcxproj]
cl : command line warning D9002: ignoring unknown option '-O3' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutoria
l\build\automobile.vcxproj]
automobile.cpp
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xmemory(154,5): error C2039:
'_invalid_parameter': is not a member of 'global namespace'' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\ build\automobile.vcxproj] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xmemory(154,5): error C3861: '_invalid_parameter': identifier not found [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vc xproj] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xmemory(164,5): error C2039: '_invalid_parameter': is not a member of 'global namespace'' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial
build\automobile.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xmemory(164,5): error C3861:
'_invalid_parameter': identifier not found [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vc
xproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xmemory(1330,9): error C2039:
'invalid_parameter': is not a member of 'global namespace'' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial \build\automobile.vcxproj] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xmemory(1330,1): error C3861: '_invalid_parameter': identifier not found [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.v cxproj] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xpolymorphic_allocator.h(135, 13): error C2039: '_invalid_parameter': is not a member of 'global namespace'' [C:\Users\beryl\source\repos\cmake_cpp
pybind11_tutorial\build\automobile.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xpolymorphic_allocator.h(135,
1): error C3861: '_invalid_parameter': identifier not found [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\bu
ild\automobile.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xpolymorphic_allocator.h(142,
13): error C2039: 'invalid_parameter': is not a member of '`global namespace'' [C:\Users\beryl\source\repos\cmake_cpp
pybind11_tutorial\build\automobile.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xpolymorphic_allocator.h(142,
1): error C3861: '_invalid_parameter': identifier not found [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\bu
ild\automobile.vcxproj]
C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build_deps\pybind11-src\include\pybind11\detail/internals.h(18
7,1): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc [C:\Users\beryl\so
urce\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxproj]
C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build_deps\pybind11-src\include\pybind11\cast.h(442,36): error
C2027: use of undefined type '_frame' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxpro
j]
c:\Users\beryl\AppData\Local\Programs\Python\Python311\include\pytypedefs.h(22,16): message : see declaration of '_fram
e' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxproj]
C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build_deps\pybind11-src\include\pybind11\cast.h(444,29): error
C2027: use of undefined type '_frame' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxpro
j]
c:\Users\beryl\AppData\Local\Programs\Python\Python311\include\pytypedefs.h(22,16): message : see declaration of '_fram
e' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxproj]
C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build_deps\pybind11-src\include\pybind11\cast.h(445,26): error
C2027: use of undefined type '_frame' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxpro
j]
c:\Users\beryl\AppData\Local\Programs\Python\Python311\include\pytypedefs.h(22,16): message : see declaration of '_fram
e' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxproj]
C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build_deps\pybind11-src\include\pybind11/pybind11.h(2032,49):
error C2039: 'frame': is not a member of 'ts' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobil
e.vcxproj]
c:\Users\beryl\AppData\Local\Programs\Python\Python311\include\cpython/pystate.h(82,8): message : see declaration of '

ts' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxproj]
C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build_deps\pybind11-src\include\pybind11/pybind11.h(2033): err
or C2027: use of undefined type '_frame' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxp
roj]
c:\Users\beryl\AppData\Local\Programs\Python\Python311\include\pytypedefs.h(22,16): message : see declaration of '_fram
e' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxproj]
C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build_deps\pybind11-src\include\pybind11/pybind11.h(2034,1): e
rror C2027: use of undefined type '_frame' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vc
xproj]
c:\Users\beryl\AppData\Local\Programs\Python\Python311\include\pytypedefs.h(22,16): message : see declaration of '_fram
e' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxproj]
C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build_deps\pybind11-src\include\pybind11/pybind11.h(2037,18):
error C2027: use of undefined type '_frame' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.v
cxproj]
c:\Users\beryl\AppData\Local\Programs\Python\Python311\include\pytypedefs.h(22,16): message : see declaration of '_fram
e' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxproj]
C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build_deps\pybind11-src\include\pybind11/pybind11.h(2037,30):
error C2027: use of undefined type '_frame' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.v
cxproj]
c:\Users\beryl\AppData\Local\Programs\Python\Python311\include\pytypedefs.h(22,16): message : see declaration of '_fram
e' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxproj]
C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build_deps\pybind11-src\include\pybind11/pybind11.h(2036,33):
error C2660: 'PyDict_GetItem': function does not take 1 arguments [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutor
ial\build\automobile.vcxproj]
c:\Users\beryl\AppData\Local\Programs\Python\Python311\include\dictobject.h(22,24): message : see declaration of 'PyDic
t_GetItem' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\automobile.vcxproj]
C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build_deps\pybind11-src\include\pybind11/pybind11.h(2036,33):
message : while trying to match the argument list '()' [C:\Users\beryl\source\repos\cmake_cpp_pybind11_tutorial\build\a
utomobile.vcxproj]

Setting up the Python wrapper cmake error

I'm having the following error while I try to run make at the setting up the Python wrapper section. May I have some help on finding out what is missing?
The output is pasted below.

(base) asanci@asanci:~/python/build$ make
Scanning dependencies of target automobile
make[2]: *** No rule to make target 'CMakeFiles/automobile.dir/build'.  Stop.
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/automobile.dir/all' failed
make[1]: *** [CMakeFiles/automobile.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.