Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 17, 2025

The Linux platform implementation was missing several critical Menu and MenuItem factory methods and member functions that were declared in the header but not implemented, causing undefined reference errors during linking.

Problem

When building the menu_example or any code using the Menu API on Linux, the linker would fail with errors like:

undefined reference to `nativeapi::Menu::Create()'
undefined reference to `nativeapi::MenuItem::Create(std::string const&, nativeapi::MenuItemType)'
undefined reference to `nativeapi::MenuItem::CreateSeparator()'

This happened because the Linux implementation in src/platform/linux/menu_linux.cpp only contained basic constructor/destructor and a few methods, while the macOS and Windows implementations had complete API coverage.

Solution

Implemented the complete Menu and MenuItem API for Linux using GTK3 widgets:

Key additions:

  • Global registry system: Added ID generators and object registries for proper lifecycle management
  • Menu::Create(): Factory method that creates GTK menu widgets and manages C++ wrapper lifecycle
  • MenuItem factory methods: Create() and CreateSeparator() with proper GTK widget creation based on MenuItemType
  • Complete MenuItem API: All missing methods including SetText(), SetEnabled(), SetState(), SetAccelerator(), Trigger(), etc.
  • Complete Menu API: All missing methods including AddItem(), GetItemCount(), ShowAsContextMenu(), etc.

GTK Integration:

  • Maps MenuItemType to appropriate GTK widgets (GtkMenuItem, GtkCheckMenuItem, GtkRadioMenuItem, GtkSeparatorMenuItem)
  • Integrates with GTK event system using g_signal_emit_by_name for menu item triggering
  • Proper memory management with g_object_unref and widget lifecycle handling
  • Maintains internal item collections for menu management operations

Testing

  • All undefined reference errors resolved
  • menu_example now compiles and links successfully on Linux
  • Implementation follows same patterns as macOS version for consistency
  • Full API compatibility maintained across all platforms

The Linux implementation now has complete feature parity with the declared interface and other platform implementations.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: lijy91 <3889523+lijy91@users.noreply.github.com>
@lijy91 lijy91 marked this pull request as ready for review September 17, 2025 13:49
Copilot AI changed the title [WIP] Fix the undefined reference to nativeapi::Menu::Create() issue on Linux Fix undefined reference to nativeapi::Menu::Create() on Linux Sep 17, 2025
@lijy91 lijy91 merged commit c07bb10 into main Sep 17, 2025
0 of 2 checks passed
Copilot AI requested a review from lijy91 September 17, 2025 13:49
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