Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra_compile_args seemingly ignored by custom BuildExt #23

Closed
mivade opened this issue Apr 27, 2017 · 3 comments · Fixed by #60
Closed

extra_compile_args seemingly ignored by custom BuildExt #23

mivade opened this issue Apr 27, 2017 · 3 comments · Fixed by #60

Comments

@mivade
Copy link

mivade commented Apr 27, 2017

Trying to adapt this to a project and add -fopenmp, I found that I get warnings about ignoring #pragma omp parallel for. Inspecting the actual compiler call, -fopenmp doesn't show up even though the extra_compile_args=['-fopenmp'] is given to the Extension.

Workaround: in BuildExt.build_extensions, add:

opts.append('-fopenmp')

A better way to do this might be to note use a custom build_ext class at all, but instead just do all the platform/compiler checking logic at the top level and passing the results in to extra_compile_args.

@xiuliren
Copy link

xiuliren commented Aug 9, 2019

adding two lines fixed this:

ct = self.compiler.compiler_type              
opts = self.c_opts.get(ct, [])                
link_opts = self.l_opts.get(ct, [])           
for arg in ext_modules[0].extra_compile_args: 
┊   opts.append(arg)                          

@ywz978020607
Copy link

Trying to adapt this to a project and add -fopenmp, I found that I get warnings about ignoring #pragma omp parallel for. Inspecting the actual compiler call, -fopenmp doesn't show up even though the extra_compile_args=['-fopenmp'] is given to the Extension.

Workaround: in BuildExt.build_extensions, add:

opts.append('-fopenmp')

A better way to do this might be to note use a custom build_ext class at all, but instead just do all the platform/compiler checking logic at the top level and passing the results in to extra_compile_args.

what is the opts variable? I need to add openmp, also found that the -fopenmp don't show up in the actual compile call.

@ywz978020607
Copy link

Oh, I see, in Pybind11Extension: add two lines:

extra_compile_args = ["-fopenmp"],
extra_link_args = ["-fopenmp"],

in

ext_modules = [
    Pybind11Extension("python_example",
        ["src/main.cpp"],
        # Example: passing in the version to the compiled code
        define_macros = [('VERSION_INFO', __version__)],
        extra_compile_args = ["-fopenmp"],
        extra_link_args = ["-fopenmp"],
        cxx_std = 11,
        language = 'c++',
        ),
]

It works out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants