是否有任何方法可以运行命令并将其输出作为G++汇编标志?

发布于 2025-01-21 14:03:06 字数 976 浏览 5 评论 0原文

我的目标是能够在WSL2中编译和运行简单的C ++程序。我想将WSL的G ++用作编译器。要编写程序,我正在使用崇高的文本用于Windows。 All my program are stored in Windows filesystem.

这是我针对C ++的崇高构建文件。

"shell_cmd": "wsl g++ -std=c++17 -fsanitize=address \"${file}\" -g -o \"${file_path}/${file_base_name}.o\"",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", 
    "working_dir": "${file_path}",
    "selector": "source.c++",

现在问题是当我尝试构建代码时,Sublime变量$ {file_path}将我的源代码的Windows文件路径传递到wsl2中安装的g ++,而wsl2和g ++无法识别路径并产生错误(如预期)。

为了克服这个问题,我想使用称为wslpath的程序,该程序将将Windows文件路径c:// some_folder转换为WSL2类型/mnt/c/c/some_folder

现在,当我尝试在Sublime Build文件中使用WSLPATH时,它会产生错误,而无需按预期工作。

我的最终崇高构建文件的shell_cmd看起来像是

"shell_cmd": "wsl g++ -std=c++17 -fsanitize=address $wslpath | \"${file}\" -g -o \"${file_path}/${file_base_name}.o\"",

我在此过程中做错了什么,或者我可以做其他事情来实现目标?

My goal is to be able to compile and run simple C++ programs in WSL2. I want to use WSL's G++ as the compiler. To write the program I am using sublime text for Windows. All my program are stored in Windows filesystem.

This is my sublime build file for C++.

"shell_cmd": "wsl g++ -std=c++17 -fsanitize=address \"${file}\" -g -o \"${file_path}/${file_base_name}.o\"",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)
quot;, 
    "working_dir": "${file_path}",
    "selector": "source.c++",

Now the problem is when I try to build the code, the sublime variable ${file_path} passes the Windows file path of my source code to g++ which is installed in WSL2 and g++ is unable to recognize the path and produces errors (as expected).

To overcome this problem I want to use the program called wslpath which will convert the Windows file path C://some_folder to WSL2 type /mnt/c/some_folder.

Now when I try to use wslpath in sublime build file, it produces error and doesnot works as expected.

My final sublime build file's shell_cmd looks like this

"shell_cmd": "wsl g++ -std=c++17 -fsanitize=address $wslpath | \"${file}\" -g -o \"${file_path}/${file_base_name}.o\"",

What am I doing wrong in the process or is there something else I can do to achieve the goal?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文