Visual Studio - X11: The DISPLAY environment varia

2019-07-27 10:03发布

I'm developing a cross-plataform (Windows / Linux) x64 GUI application, using Visual Studio 2019 Enterprise.

In this 2019 edition we can use Visual Studio to debug both plataforms (Windows - Native) and Linux - Ubuntu (Running in a Virtual Machine).

You can see it here: https://devblogs.microsoft.com/cppblog/using-visual-studio-for-cross-platform-c-development-targeting-windows-and-linux/

So, I followed this tutorial and I got this GUI example application running and debugging in my Ubuntu 18 VM using Visual Studio 2019 IDE. Perfect!

Now, I tried to do my custom GUI application:

To do a cross-plataform GUI, I'm using GLFW 3.3.

Steps:

  1. Create a Visual Studio CMake Project

  2. Write the C++ code and CMakeLists.txt

  3. Add Both VS debug configurations (Windows x64 and Linux x64)

  4. Compile and Link (OK on both VS Windows and Linux targets)

  5. Run (Ok on both VS Windows and Linux targets)

But...

When I run it in Windows setup, I got all ok...a GLFW window shows up...good! When I run it in Linux-debug (by Visual Studio), when the VS debuger hits glfwInit() line, I got this error:

Starting GLFW context, OpenGL 3.3

Glfw Error 65544: X11: The DISPLAY environment variable is missing

So, when I select the Linux debug configuration I got NO GUI Window in my VM.

Searching on internet, I saw that is necessary say to Visual Studio to export the DISPLAY linux enviroment variable inside the launch.vs.json file.

You can see it here: https://docs.microsoft.com/en-us/cpp/build/get-started-linux-cmake?view=vs-2019

Inside my VM Ubuntu, I got DISPLAY:0

Then, my launch.vs.json file I wrote:

"export DISPLAY=:0;${debuggerCommand}"

or

"export DISPLAY=:0.0;${debuggerCommand}"

Details:

IF I manually go inside my Ubuntu VM, and double-click in the compiled application, it shows up the GLFW window and all goes Ok!

My problem is:

How can I export the DISPLAY enviroment variable to the Linux VM using Visual Studio 2019 IDE to debug my application that will run inside the Virtual Box (VM).

0条回答
登录 后发表回答