Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include the path needed by C++ in cython?

Tags:

c++

python

cython

I managed to get Cython working for a simple C++ file. But when I tried to get it to work for our project, I got a path issue.

When I run "python3.6 setup.py build_ext --inplace", I got these errors:

myapp.h:12:10: fatal error: base/file1.h: No such file or directory
 #include <base/file1.h>
          ^~~~~~~~~~~

Here is my folder structure:

.
|-- base
|   |-- file1.h
|   \-- file1.cpp
|
|-- app
|   |-- app.pyx
|   \-- setup.py
|
|-- myapp.cpp
\-- myapp.h

Here is the setup.py:

from distutils.core import setup, Extension
from Cython.Build import cythonize

setup(ext_modules = cythonize(Extension(
    "app",
    sources=["app.pyx", "myapp.cpp"],
    language="c++",
)))

In myapp.h, there is this line:

#include <base/file1.h>
like image 248
user1556331 Avatar asked Dec 06 '25 14:12

user1556331


1 Answers

You're looking for the include_dirs parameter of setup. In your case, this should work:

setup(...
    include_dirs = ['.'],
     ... )

Or maybe '..', your directory tree is a bit unusual.

like image 91
Demi-Lune Avatar answered Dec 09 '25 03:12

Demi-Lune