为C++设置Visual Studio代码的工作目录项目

发布于 2025-01-24 12:04:50 字数 736 浏览 3 评论 0原文

我在Visual Studio代码中有一个C ++项目,并且正在尝试设置工作目录,以便我可以执行“ Assets/model.obj”以访问模型,而不必传递整个c:/users/.. 。路径。经过一些研究,我发现您需要在启动下进行以下操作。

"configurations": [{"currentDir": "${workspaceRoot}/"}],
"program": "${file}",
"cwd": "${fileDirname}"   

但是,这似乎对我不起作用。我如何为C ++项目设置工作目录?

基于建议的更新配置(仅在按DEBUG模式下工作时,按F5和当前文件为Main.CPP)

"configurations": [
    {
        "name": "(Windows) Launch",
        "type": "cppvsdbg",
        "request": "launch",
        "program": "${workspaceFolder}/build/Debug/App.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${fileDirname}",
        "environment": [],
        "console": "externalTerminal",
    }
]

I have a C++ project in Visual Studio Code and I am trying to set the working directory so I can do "Assets/model.obj" to access a model instead of having to pass the entire C:/users/... path. After some research I have found that you need to do the following inside launch.json

"configurations": [{"currentDir": "${workspaceRoot}/"}],
"program": "${file}",
"cwd": "${fileDirname}"   

However, this does not seem to work for me. How might I set the working directory for my C++ project?

Updated configuration based on suggestions (Working only in Debug mode when pressing F5 and current file is main.cpp)

"configurations": [
    {
        "name": "(Windows) Launch",
        "type": "cppvsdbg",
        "request": "launch",
        "program": "${workspaceFolder}/build/Debug/App.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${fileDirname}",
        "environment": [],
        "console": "externalTerminal",
    }
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落叶缤纷 2025-01-31 12:04:50

如提到的评论中:

在启动中“ cwd”中的路径与“程序”中所述的配置相同。喜欢:

"configurations": [
{
    "name": "(Windows) Launch",
    "type": "cppvsdbg",
    "request": "launch",
    "program": "${workspaceFolder}/build/Debug/App.exe",
    "args": [],
    "stopAtEntry": false,
    "cwd": "${workspaceFolder}/build/Debug/",
    "environment": [],
    "console": "externalTerminal",
}

]

然后将您的资产复制到构建/调试 - 文件夹。您可以进行调试。

As in the comments mentioned:

put the same path in "cwd" in launch.json under configuration as stated in "program". Like:

"configurations": [
{
    "name": "(Windows) Launch",
    "type": "cppvsdbg",
    "request": "launch",
    "program": "${workspaceFolder}/build/Debug/App.exe",
    "args": [],
    "stopAtEntry": false,
    "cwd": "${workspaceFolder}/build/Debug/",
    "environment": [],
    "console": "externalTerminal",
}

]

Then copy your Assets to the build/Debug - folder. And you can run Debugging.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文