Nyc*_*aia 5 linux cross-platform visual-studio visual-studio-2017 visual-studio-2019
我正在使用 Visual Studio 2019 Enterprise 开发跨平台 (Windows / Linux) x64 GUI 应用程序。
在这个 2019 版本中,我们可以使用 Visual Studio 来调试平台(Windows - 本机)和 Linux - Ubuntu(在虚拟机中运行)。
因此,我按照本教程进行操作,并使用 Visual Studio 2019 IDE 在我的 Ubuntu 18 VM 中运行和调试此 GUI 示例应用程序。完美的!
现在,我尝试做我的自定义 GUI 应用程序:
为了实现跨平台 GUI,我使用 GLFW 3.3。
脚步:
创建 Visual Studio CMake 项目
编写C++代码和CMakeLists.txt
添加 VS 调试配置(Windows x64 和 Linux x64)
编译和链接(在VS Windows 和 Linux 目标上都可以)
运行(在 VS Windows 和 Linux 目标上都可以)
但...
当我在 Windows 设置中运行它时,一切正常...出现 GLFW 窗口...很好!
当我在 Linux 调试(通过 Visual Studio)中运行它时,当 VS 调试器命中行时glfwInit(),我收到此错误:
Starting GLFW context, OpenGL 3.3
Glfw Error 65544: X11: The DISPLAY environment variable is missing
因此,当我选择 Linux 调试配置时,我的虚拟机中没有 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-添加"export DISPLAY=:0;"内部pipeArgs
6- 拆下线路"processId: 0"。通过这一行,只有root用户才能在Linux上进行部署和调试。
7- 在 pipelineArgs: 内添加新行"--tty=${debugInfo.tty}"。VS2019创建CMake项目时不会自动生成这一行
所以 pipelineArgs 是:
"pipeArgs": [
"/s",
"${debugInfo.remoteMachineId}",
"/p",
"${debugInfo.parentProcessId}",
"/c",
"export DISPLAY=:0;${debuggerCommand}",
"--tty=${debugInfo.tty}"
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7959 次 |
| 最近记录: |