Skip to content

Fix desktop_drop Linux snap build failure due to missing stdlib.h include #425

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

Merged
merged 2 commits into from
Jul 22, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 22, 2025

Summary

Fixes compilation error when building Linux snap packages that use the desktop_drop plugin. The error occurred because std::getenv was used without the proper header include.

Error Details

When building a snap with snapcraft --use-lxd, the build failed with:

/root/parts/desktop-drop-example/build/linux/flutter/ephemeral/.plugin_symlinks/desktop_drop/linux/desktop_drop_plugin.cc:69:29: error: no member named 'getenv' in namespace 'std'; did you mean simply 'getenv'?

Root Cause

The code was calling std::getenv("XDG_CURRENT_DESKTOP") without including <cstdlib> or <stdlib.h>, which provide the getenv function. While this might work in some build environments due to transitive includes, snap builds with stricter compilation flags exposed this missing dependency.

Solution

  • Added #include <stdlib.h> to provide access to the getenv function
  • Changed std::getenv to getenv for consistency with other C functions used in the same file (like strcmp, g_ascii_strdown, etc.)

Changes Made

 #include <flutter_linux/flutter_linux.h>
 #include <gtk/gtk.h>
+#include <stdlib.h>
 #include <sys/utsname.h>

 ...

 static void desktop_drop_plugin_init(DesktopDropPlugin *self) {
-  const char * desktopEnv = std::getenv("XDG_CURRENT_DESKTOP");
+  const char * desktopEnv = getenv("XDG_CURRENT_DESKTOP");
   if (desktopEnv) {

Testing

  • Verified the fix compiles correctly with standard gcc
  • Tested getenv functionality works as expected
  • No behavioral changes - only fixes the compilation issue

Fixes #424.


💡 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: boyan01 <17426470+boyan01@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [desktop_drop] Linux snap build fails due to std::getenv not available Fix desktop_drop Linux snap build failure due to missing stdlib.h include Jul 22, 2025
@Copilot Copilot AI requested a review from boyan01 July 22, 2025 03:09
Copilot finished work on behalf of boyan01 July 22, 2025 03:09
@boyan01 boyan01 marked this pull request as ready for review July 22, 2025 03:22
@boyan01 boyan01 merged commit b29e87f into main Jul 22, 2025
2 checks passed
@boyan01 boyan01 deleted the copilot/fix-424 branch July 22, 2025 03:22
Copilot AI added a commit that referenced this pull request Jul 22, 2025
Co-authored-by: boyan01 <17426470+boyan01@users.noreply.github.com>
boyan01 added a commit that referenced this pull request Jul 22, 2025
* Initial plan

* Bump desktop_drop version to 0.6.1

Co-authored-by: boyan01 <17426470+boyan01@users.noreply.github.com>

* Update changelog to reference actual fix from PR #425

Co-authored-by: boyan01 <17426470+boyan01@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: boyan01 <17426470+boyan01@users.noreply.github.com>
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.

[desktop_drop] Linux snap build fails due to std::getenv not available
2 participants