pybind11 compile_cpp_code specifying include_dirs, library_dirs and linking against external libraries


96
views
1
3 months ago by
I would need to compile a C++ extension that uses external libraries. Before the advent of pybind11 I could write
compiled_code = compile_extension_module(code=some_code, cppargs=["-O3", "-g"], include_dirs = ["/path/to/include/"], library_dirs = ["/path/to/library/dir/"], libraries = ["libraryname"])

​
How do I do this now with compile_cpp_code (or equivalent)? I would need to specify include and library directories and to link against external libraries.
Community: FEniCS Project
1
I think that compile_cpp_code might need some effort to make it fulfill your needs. So contributing is probably a right way.
written 3 months ago by Jan Blechta  
Ok, I think it is an easy fix. I made a pull request https://bitbucket.org/fenics-project/dolfin/pull-requests/472/updated-pybind11jitpy-so-that/diff
written 3 months ago by Matteo Croci  
From https://bitbucket.org/fenics-project/dolfin/src/06d2cdc78a64c764eab85031fcfd79e48b0b7a5c/python/dolfin/jit/pybind11jit.py#lines-54 I'd say just from dolfin.jit.jit import dolfin_pc and append dolfin_pc["library_dirs"] before the actual compilation. But I didn't try it.
written 3 months ago by Michal Habera  
1
Seems to be a hack rather than a suitable replacement of the required functionality.
written 3 months ago by Jan Blechta  
Sure, it is ugly hack. Therefore a comment not an answer, ;)
written 3 months ago by Michal Habera  

1 Answer


4
11 weeks ago by
Thanks Michal and Jan. The pull request I made is now merged. Now one can do

compiled_code = compile_cpp_code(code=some_code, cppargs=["-O3", "-g"], include_dirs = ["/path/to/include/"], library_dirs = ["/path/to/library/dir/"], libraries = ["libraryname"])​
Please login to add an answer/comment or follow this question.

Similar posts:
Search »