pybind11 compile_cpp_code specifying include_dirs, library_dirs and linking against external libraries

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
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
written 3 months ago by Matteo Croci  
From 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  
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

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 »