Skip to content

fix(linux): build with GLib older than 2.74 - #89

Merged
lijy91 merged 1 commit into
libnativeapi:mainfrom
JMGomes:fix/linux-glib-2.72-connect-flags
Nov 3, 2026
Merged

lijy91 merged 1 commit into
libnativeapi:mainfrom
JMGomes:fix/linux-glib-2.72-connect-flags

Conversation

@JMGomes

@JMGomes JMGomes commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

I'm blocked from using this library in flutter - On Ubuntu 22.04, the library does not build. shortcut_portal_linux.cpp fails to compile:

src/platform/linux/shortcut_portal_linux.cpp:429:19: error: 'G_CONNECT_DEFAULT' was not declared in this scope; did you mean 'G_CONNECT_AFTER'?

The same error stops every Flutter app that depends on cnativeapi 0.5.6 or 0.5.7 (for example through tray_manager 0.8.x or window_manager 0.6.x), because the native-assets build hook compiles all sources:

ERROR: Building assets for package:cnativeapi failed.
.../cnativeapi-0.5.7/cxx_impl/src/platform/linux/shortcut_portal_linux.cpp:429:19: error: use of undeclared identifier 'G_CONNECT_DEFAULT'; did you mean 'G_CONNECT_AFTER'?

Ubuntu 22.04 is still a common build host, because a Linux app must be built on the oldest distribution that it supports.

Root cause

GLib added G_CONNECT_DEFAULT in 2.74 (GConnectFlags: "Value: 0. Available since: 2.74"). Ubuntu 22.04 ships GLib 2.72.4. The README asks only for GTK 3, X11 and Xi, and application_linux.cpp already guards G_APPLICATION_DEFAULT_FLAGS with GLIB_CHECK_VERSION(2, 74, 0) for older distributions. The Wayland shortcut portal code from 0.5.6 added a new use of a GLib 2.74 name without such a guard. CI uses ubuntu-latest (24.04, GLib 2.80), so it does not see the error.

Fix

Pass static_cast<GConnectFlags>(0). G_CONNECT_DEFAULT has the value 0, so the behavior does not change on any GLib version.

Verification

I built the repository in an ubuntu:22.04 container (Ubuntu 22.04.5, GLib 2.72.4, GCC 11.4, CMake 3.22) with the same steps as the Linux CI job:

  • main (472b2ad): the build fails with the error above.
  • This change: the library and all examples build.

I also compiled the cxx_impl sources of the published cnativeapi 0.5.7 package with clang 14 on the same image. With this change, all 102 Linux sources compile, and the shared library links.

A Linux CI job on ubuntu-22.04 would catch this kind of error. I can add one in a separate PR if you want.

🤖 Generated with Claude Code

G_CONNECT_DEFAULT was added in GLib 2.74. Ubuntu 22.04 ships GLib 2.72,
so shortcut_portal_linux.cpp does not compile there, and the whole
library fails to build. Pass the value 0 directly, the same flags value
on every GLib version.
@JMGomes

JMGomes commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@lijy91 kindly asking for a review here 🙏

@lijy91 lijy91 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zero-valued GConnectFlags cast preserves the existing signal behavior and avoids the GLib 2.74-only enum name. No actionable findings; all CI build jobs pass.

@lijy91
lijy91 merged commit cff78fa into libnativeapi:main Nov 3, 2026
9 checks passed

lijy91 commented Nov 3, 2026

Copy link
Copy Markdown
Member

Thanks @JMGomes for the fix and the detailed verification on Ubuntu 22.04!

This is now merged and included in v0.5.8. cnativeapi, nativeapi, and nativeapi_flutter 0.5.8 are all available on pub.dev with this fix.

@JMGomes

JMGomes commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

ctionable findings; all CI build jobs pass.

Thanks! will use it ASAP

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 this pull request may close these issues.

2 participants