question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gnome.generate_gir incorrectly filters clang cflags like -W , passed to g-ir-scanner, and gcc fails

See original GitHub issue

Describe the bug

The symptom is that, using clang, meson calls g-ir-scanner which calls gcc which fails with something like

 "gcc: error: unrecognized command-line option ... -Wsometimes-unitialized"

It seems that gnome.generate_gir is passing clang specific c flags to generate warnings, but g-ir-scanner calls gcc, and gcc fails, not recognizing flags specific to clang compiler.

To Reproduce

The case is a meson build of the GIMP app v2.99, using clang, on Linux, Alpine or Ubuntu.

Analysis and suggested fix

In the code for gnome.generate_gir there is this:

def _get_scanner_cflags(cflags):
        'g-ir-scanner only accepts -I/-D/-U; must ignore all other flags'
        for f in cflags:
            if f.startswith(('-D', '-U', '-I')):
                yield f

So it seems that the intent is to filter out all the -W flags.

But later:

        cflags, internal_ldflags, external_ldflags = self._get_langs_compilers_flags(state, langs_compilers)
        ...omitted...
        dep_cflags, dep_internal_ldflags, dep_external_ldflags, gi_includes = \
            self._get_dependencies_flags(deps, state, depends, use_gir_args=True)
        cflags += list(self._get_scanner_cflags(dep_cflags))

In the above, cflags is initially an unfiltered list of cflags, and then the code appends more cflags that are filtered by calls to _get_scanner_cflags().

I believe a fix is to add one line like so:

cflags, internal_ldflags, external_ldflags = self._get_langs_compilers_flags(state, langs_compilers)
cflags = list(self._get_scanner_cflags(cflags))

That is, immediately filter the initial contents of the variable cflag.

I tested this fix minimally, only to build GIMP. The meson build of GIMP is “experimental”, not used for releases.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ebassicommented, Jun 23, 2021

I’ve opened an MR for gobject-introspection that adds a --compiler command line to g-ir-scanner. Hopefully, it’ll be available in the next gobject-introspection release in September.

0reactions
cgrzembacommented, Oct 1, 2022

I have created #10875

Read more comments on GitHub >

github_iconTop Results From Across the Web

g-ir-scanner should not use system-provided CFLAGS - GitLab
g-ir-scanner invokes the CC compiler with both the CFLAGS and the flags from the python installation. These flags can conflict and g-ir-scanner ...
Read more >
Error with gcc but not with clang when compiling initializer list ...
This seems like a bug in the gcc compiler. Interestingly, it works if you do +Task<int> which implies the &Task<int> might have a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found