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

Unable to build extension with mixed C and C++ sources #27

Closed
junwei-wang opened this issue Feb 4, 2021 · 4 comments
Closed

Unable to build extension with mixed C and C++ sources #27

junwei-wang opened this issue Feb 4, 2021 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@junwei-wang
Copy link

	Extension(
        'model.A',
        sources=['model/a.i',
                 'model/a.cpp',
                 'model/b.c'],
        swig_opts=["-c++"],
        extra_compile_args=["-std=c++11"],
    ),

The code above won't compile on macOS. clang complains that -std=c++ could not be used for C source code (i.e. b.c).

There is a quick fix for my issue on this line:

src, ext = build[obj]

        cc_args = copy(cc_args)
        extra_postargs = copy(extra_postargs)
        if ext == '.c':
            if '-std=c++11' in cc_args:
                cc_args.remove('-std=c++11')
            if '-std=c++11' in extra_postargs:
                extra_postargs.remove('-std=c++11')

However, this is a not decent solution to the cause of the issue.

@jaraco jaraco changed the title Compliaton flag bug Unable to build extension with mixed C and C++ sources Dec 11, 2021
@jaraco
Copy link
Member

jaraco commented Dec 11, 2021

This sounds like a feature request rather than a bug. It appears to me you're attempting to build an extension that includes both C++ and C sources, but in the parameters to the extension, you're specifying C++ to the compiler. I'm not surprised the compiler complains.

I think you're after a feature that does not yet exist.

I agree, the patch provided isn't particularly robust. I suspect what you're after is a more sophisticated extension-building mechanism that understands how to build and link from different source languages.

I welcome your or others to work on a solution.

@jaraco jaraco added enhancement New feature or request help wanted Extra attention is needed labels Dec 11, 2021
@mgorny
Copy link
Contributor

mgorny commented Jan 24, 2022

Not sure if it's going to be helpful but Gentoo has historically carried a large distutils patch with some parts related to C++ compiling. Unfortunately, it was undocumented and nobody really cared to figure out why exactly it was needed. It can be grabbed e.g. from https://gitweb.gentoo.org/fork/cpython.git/commit/?h=gentoo-3.10.0_p1&id=11d9404f6bd865155fbc861b483f2d99afcd74e4

@jaraco jaraco closed this as completed in 2667241 Jul 1, 2023
@mgorny
Copy link
Contributor

mgorny commented Jul 2, 2023

@jaraco, seems like this bug was closed by accident.

@jaraco jaraco reopened this Jul 3, 2023
@jaraco
Copy link
Member

jaraco commented Jul 3, 2023

Gah. What a mess. Thanks for letting me know.

@junwei-wang junwei-wang closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants