gpt4 book ai didi

linux - Visual Studio -X11 : The DISPLAY environment variable is missing

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:31:58 26 4
gpt4 key购买 nike

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

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

你可以在这里看到: 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 示例应用程序。 完美!

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

为了实现跨平台 GUI,我使用的是 GLFW 3.3。

步骤:

  1. 创建 Visual Studio CMake 项目

  2. 编写C++代码和CMakeLists.txt

  3. 添加 VS 调试配置(Windows x64 和 Linux x64)

  4. 编译和链接(OK on both VS Windows 和 Linux 目标)

  5. 运行(在 Windows 和 Linux 目标上均正常)

但是……

当我在 Windows 设置中运行它时,一切正常...出现 GLFW 窗口...很好!当我在 Linux-debug(通过 Visual Studio)中运行它时,当 VS 调试器点击 glfwInit() 行时,我得到了这个错误:

启动 GLFW 上下文,OpenGL 3.3

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

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

在互联网上搜索,我看到有必要告诉 Visual Studio 在 launch.vs.json 文件中导出 DISPLAY linux 环境变量。

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

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

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

“export DISPLAY=:0;${debuggerCommand}”

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

详细信息:

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

我的问题是:

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

最佳答案

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

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

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

1- 设置一个 "name": "helloworld"。默认值为 ""

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

3- 设置 "projectTarget": "helloworld"。此属性不会由 VS 2019 自动创建。

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

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

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

7- 在 pipeArgs 中添加新行:"--tty=${debugInfo.tty}"。当您创建 CMake 项目 VS2019 时,此行不会自动生成

所以 pipeArgs 是:

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

关于linux - Visual Studio -X11 : The DISPLAY environment variable is missing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56743033/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com