Visual Studio-X11:DISPLAY环境变量丢失 [英] Visual Studio - X11: The DISPLAY environment variable is missing

查看:278
本文介绍了Visual Studio-X11:DISPLAY环境变量丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2019 Enterprise开发跨平台(Windows/Linux)x64 GUI应用程序.

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

在此2019版中,我们可以使用Visual Studio 调试平台(Windows-本机)和Linux-Ubuntu(在虚拟机中运行).

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

您可以在这里看到它: https://devblogs.microsoft.com/cppblog/using-visual-studio-for-cross-platform-c-development-targeting-windows-and-linux/

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

因此,我遵循了本教程,并使用Visual Studio 2019 IDE在Ubuntu 18 VM中运行和调试了这个GUI示例应用程序.完美!

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!

现在,我尝试做我的自定义GUI应用程序:

Now, I tried to do my custom GUI application:

要创建跨平台的GUI,我使用的是GLFW 3.3.

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

步骤:

  1. 创建一个Visual Studio CMake项目

  1. Create a Visual Studio CMake Project

编写C ++代码和CMakeLists.txt

Write the C++ code and CMakeLists.txt

添加两个VS调试配置(Windows x64和Linux x64)

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

编译和链接(在VS Windows和Linux目标上均为确定)

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

运行(在Windows和Linux目标上均确定)

Run (Ok on both VS Windows and Linux targets)

但是...

当我在Windows安装程序中运行它时,一切正常...出现了GLFW窗口... 好!当我在Linux调试程序(由Visual Studio)中运行它时,当VS调试器命中 glfwInit()行时,出现此错误:

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:

启动GLFW上下文,OpenGL 3.3

Glfw错误65544:X11:缺少DISPLAY环境变量

因此,当我选择Linux调试配置时,我的VM中没有GUI窗口.

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

在Internet上搜索时,我看到有必要对Visual Studio说"",以便在launch.vs.json文件中导出DISPLAY linux环境变量.

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.

您可以在这里看到它: https://docs.microsoft.com/en-us/cpp/build/get-started-linux-cmake?view=vs-2019

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

在我的VM Ubuntu中,我得到了 DISPLAY:0

Inside my VM Ubuntu, I got DISPLAY:0

然后,我写了我的launch.vs.json文件:

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

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

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

详细信息:

如果我手动进入我的Ubuntu VM,然后双击已编译的应用程序,它将显示GLFW窗口,并且一切正常!

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!

我的问题是:

如何使用Visual Studio 2019 IDE将DISPLAY环境变量导出到Linux VM以调试将在Virtual Box(VM)中运行的应用程序.

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).

推荐答案

Microsoft C ++团队的一些好人(感谢Ion,Erika和Elisabeth)帮助我,我找到了解决方案.

Some nice guys of Microsoft C++ Team (thanks Ion, Erika and Elisabeth) help me and I found the solution.

问题与Visual Studio 自动生成的"launch.json"文件有关.

The problem is related with the Visual Studio automatic generated "launch.json" file.

哪些"launch.json"属性我必须更改:

What "launch.json" properties I had to change:

1-设置"name":"helloworld" .默认值为" .

1- Set a "name": "helloworld". The default value is " ".

2-设置"project":"CMakeLists.txt" .默认值为" .

2- Set "project": "CMakeLists.txt". The default value is " ".

3-设置"projectTarget":"helloworld" .此属性不是VS 2019自动创建的.不是.

3- Set "projectTarget": "helloworld". This property is not created automatically by VS 2019.

4-设置"cwd":"$ {debugInfo.defaultWorkingDirectory}" .默认值为"$ {debugInfo.defaultRemoteDirectory}"

4- Set "cwd": "${debugInfo.defaultWorkingDirectory}". The default value is "${debugInfo.defaultRemoteDirectory}"

5-在pipeArgs中添加"export DISPLAY =:0;"

5- Add "export DISPLAY=:0;" inside pipeArgs

6-删除行"processId:0" .通过此行,只有root用户可以在Linux上进行部署和调试.

6- Remove the line "processId: 0". With this line, only the root user can deploy and debug on Linux.

7-在pipeArgs中添加新行:-tty = $ {debugInfo.tty}" .创建CMake Project VS2019时自动生成此行

7- Add a new line inside pipeArgs: "--tty=${debugInfo.tty}". This line is not automatically generated when you create a CMake Project VS2019

所以pipeArgs是:

So pipeArgs is:

"pipeArgs": [
          "/s",
          "${debugInfo.remoteMachineId}",
          "/p",
          "${debugInfo.parentProcessId}",
          "/c",
          "export DISPLAY=:0;${debuggerCommand}",
          "--tty=${debugInfo.tty}"
        ]

这篇关于Visual Studio-X11:DISPLAY环境变量丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆