-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
I am using PyBind11 to make a Python project.
My directory structure looks a like this:
./
my_pkg/
__init__.py
func1.py
func2.py
My C++ code looks like this:
int myfunc(){
return 1;
}
PYBIND11_PLUGIN(cppmodule) {
py::module m("cppmodule", "My cpp module");
m.def("myfunc",&myfunc,"This does stuff");
return m.ptr();
}
And my setup.py looks like this:
from setuptools import setup, Extension
import glob
ext_modules = [
Extension(
"cppmodule",
glob.glob('src/*.cpp'),
include_dirs = ['lib/include', 'lib/pybind11/'],
language = 'c++',
extra_compile_args = ['-std=c++17'],
define_macros = [('DOCTEST_CONFIG_DISABLE',None)]
)
]
setup(name = 'bob',
version = '0.1',
description = 'A package about shrimp',
url = 'http://github.com/shrimp',
author = 'Bob',
author_email = '',
license = 'MIT',
ext_modules = ext_modules
)
Now, if I runn
python setup.py install
everything compiles.
But here's the odd part, later, I can run import cppmodule but not import bob.
What I have not figured out how to do, but what I would like to do, is to have the C++ code incorporated into the bob module the same way func1 and func2 will be, so that I can type bob.myfunc() in Python.
How can I do this?
Put another way, my package contains some code that it makes sense to write in Python and other code that it makes sense to write in C++, and I'd like to include both in the same package
nschloe, benmaier, sschnug, drewcassidy, virgesmith and 4 more
Metadata
Metadata
Assignees
Labels
No labels