Search code examples
pythonc++visual-studiopybind11

How to define the include & lib path when building pybind11 proj


I am building a pybind11 project with Visual Studio (2017). The setup file is like below:


from setuptools import setup, Extension
import pybind11

# The following is for GCC compiler only.
#cpp_args = ['-std=c++11', '-stdlib=libc++', '-mmacosx-version-min=10.7']
cpp_args = []

sfc_module = Extension(
    'test_sample',
    sources=['Test.cpp'],
    include_dirs=[pybind11.get_include()],
    language='c++',
    extra_compile_args=cpp_args,
    )

setup(
    name='test_sample',
    version='1.0',
    description='Python package with Test C++ extension (PyBind11)',
    ext_modules=[sfc_module],
)

Then in the windows power shell, I will run

python setup.py build

However it complains cannot find multiple include files, I believe it will complain about missing library files later too:

C:\VS2017Pro\VC\Tools\MSVC\xxxx\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Anaconda3_CS\lib\site-packages\pybind11\include -IC:\Anaconda3_CS\include -IC:\Anaconda3_CS\include -IC:\VS2017Pro\VC\Tools\MSVC\xxxx\ATLMFC\include -IC:\VS2017Pro\VC\Tools\MSVC\xxxx\include /EHsc /TpCppPython.cpp /Fobuild\temp.win-amd64-3.7\Release\Test.obj
Test.cpp

Z:\test_pybind11\stdafx.h(8): fatal error C1083: Cannot open include file: 'targetver.h': No such file or directory

I know where this targetver.h is, just don't know how to add its location to the include path.

Your help will be greatly appreciated.


Solution

  • I know where to add more include paths, and the lib paths. One need to add them in the system environment variables: INCLUDE and LIB. Control Panel->Edit Environment Variable. Then add all the intended paths for include files to the variable INCLUDE, and add all the library paths to the variable LIB. Then the rebuild should be successful.