简体   繁体   中英

Failed to open X11 display - How to execute SFML output on WSL - Load WSL GUI apps

have any of you tried compile and executing SFML c++ project output on wsl? I tried and got

Failed to open X11 display; make sure the DISPLAY environment variable is set correctly
Aborted

Is it possible at all to execute GUI applications through wsl?

(I've installed ubuntu's for wsl)

Linux distributions set up for WSL 1 will not function with Linux GUI applications, which are only supported with WSL 2.

Due to the official documentation from Microsoft regarding WSL, you might need to check these steps:

Select Start, type PowerShell, right-click Windows PowerShell, and then select Run as administrator. after that type this command and then press enter:

wsl --update

You will need to restart WSL for the update to take effect. You can restart WSL by running the shutdown command in PowerShell.

wsl --shutdown

now, once again open powershell and type in this command:

wsl --list --verbose

You should see the number 2 for your installed distro under the heading VERSION in the response.

If everything went as planned until this point, see if your distro can open any windows by installing a GUI app like gedit and trying to open it:

sudo apt update

now install gedit:

sudo apt install gedit -y

After the installation has finished, launch gedit by typing gedit in your wsl terminal. A window from wsl inside of Windows should now open, and the issue should now be resolved.

find more information here:https://docs.microsoft.com/en-us/windows/wsl/tutorials/gui-apps

If you went on the same problem

first, you need to install VcXsrv and X11 for executing GUI applications through wsl

then you have to add these 2 to your Linux subsystem environment variables:

export DISPLAY=:0

export LIBGL_ALWAYS_INDIRECT=0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM