# glfwInit() failing with Wayland: Failed to connect to display

**URL:** <https://discourse.glfw.org/t/glfwinit-failing-with-wayland-failed-to-connect-to-display/2621>\
**Category:** support\
**Created:** [May 4, 2024, 1:31am UTC](https://discourse.glfw.org/t/glfwinit-failing-with-wayland-failed-to-connect-to-display/2621 "2024-05-04T01:31:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamincollins](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/jamincollins/32/907_2.png) [@jamincollins](https://discourse.glfw.org/u/jamincollins)\
**Post date:** [May 4, 2024, 1:31am UTC](https://discourse.glfw.org/t/glfwinit-failing-with-wayland-failed-to-connect-to-display/2621/1 "2024-05-04T01:31:23Z")

</div>

I’m attempting to initialize GLFW on an X11 session, but it is failing with the following:

error code: 65544  
description: Wayland: Failed to connect to display

I have the following environment variables set:

```auto
XDG_SESSION_TYPE=x11
GDK_BACKEND=x11

```

Code segment:

```const
    int code;
    int ret = glfwInit();
    if (ret == GLFW_FALSE) {
        code = glfwGetError(&description);
        std::cerr << "glfwInit return error, code " << code;
        if (description)
            std::cerr << ": " << description;
        std::cerr << std::endl;
        abort();
    }

```

On Arch Linux, the `glfw` package supports both X11 and Wayland AFAIK.

---

<div class="post-metadata">

**Author:** ![hypatia-of-sva](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/hypatia-of-sva/32/906_2.png) [@hypatia-of-sva](https://discourse.glfw.org/u/hypatia-of-sva)\
**Post date:** [May 4, 2024, 10:50am UTC](https://discourse.glfw.org/t/glfwinit-failing-with-wayland-failed-to-connect-to-display/2621/2 "2024-05-04T10:50:42Z")

</div>

Did you set the init hint GLFW\_PLATFORM? It may be that since that was introduced the environment variable doesn’t matter. In any way, I would so something like this:

```auto
if(glfwPlatformSupported(GLFW_PLATFORM_WIN32)) glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WIN32);
else if(glfwPlatformSupported(GLFW_PLATFORM_COCOA)) glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_COCOA);
else if(glfwPlatformSupported(GLFW_PLATFORM_X11)) glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
else if(glfwPlatformSupported(GLFW_PLATFORM_WAYLAND)) glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);
else {
        fprintf(stderr, "Error: could not find acceptable platform for GLFW\n");
        abort();
}

```

before the code you have written above (maybe rearrange the cases for whatever priority you want to have). Maybe you can try if somthing like that helps your case.

---

<div class="post-metadata">

**Author:** ![elmindreda](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/elmindreda/32/26_2.png) [@elmindreda](https://discourse.glfw.org/u/elmindreda)\
**Post date:** [May 5, 2024, 4:15pm UTC](https://discourse.glfw.org/t/glfwinit-failing-with-wayland-failed-to-connect-to-display/2621/3 "2024-05-05T16:15:46Z")

</div>

> description: Wayland: Failed to connect to display

This error description indicates that GLFW was compiled with only Wayland support. What does the GLFW [version string](https://www.glfw.org/docs/3.4/intro#intro_version_string) say?

---

<div class="post-metadata">

**Author:** ![skynet](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@skynet](https://discourse.glfw.org/u/skynet)\
**Post date:** [February 16, 2025, 7:34pm UTC](https://discourse.glfw.org/t/glfwinit-failing-with-wayland-failed-to-connect-to-display/2621/4 "2025-02-16T19:34:02Z")

</div>

This worked for me!  
I was having a similar issue but oddly enough it either would or wouldn’t work depending on how I started my binary…  
opening it from the file explorer, kitty terminal or the gnome terminal worked just fine, but for some reason Alacritty specifically just had a really big issue figuring out how to start a glfw window
