【发布时间】:2020-03-29 16:14:28
【问题描述】:
我已经开始在 Kali Linux 2019.4 上使用 Visual Studio Code。我正在使用 Code Runner 扩展编译 C 代码。我遇到了一个问题,即在launch.json 中通过“args”:[“String1”,“String2”] 传递给应用程序的参数没有传递给应用程序,如下面的输出所示:
输出:
[Running] cd "/home/user/Desktop/test/" && gcc test.c -o test && "/home/user/Desktop/test/"test
Length of argv is: 1
Arg 1 is: /home/user/Desktop/test/test
Arg 2 is: (null)
Arg 3 is: GJS_DEBUG_TOPICS=JS ERROR;JS LOG
Missing argument
[Done] exited with code=1 in 1.166 seconds
参数未通过的原因可能是什么?我在下面包含了 C 代码和 launch.json 内容:
C 代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
printf("Length of argv is: %d\n", argc);
printf("Arg 1 is: %s\n", argv[0]);
printf("Arg 2 is: %s\n", argv[1]);
printf("Arg 3 is: %s\n", argv[2]);
if (argc < 3)
{
printf("Missing argument\n");
exit(1);
}
printf("Arg 1 is %s\n", argv[1]);
printf("Arg 2 is %s\n", argv[2]);
return 0;
}
launch.json:
"version": "0.2.0",
"configurations": [
{
"name": "gcc build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": ["String1","String2"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
【问题讨论】:
-
据我所知它应该可以工作。你确定你正在运行这个任务吗?
-
是的,我使用 F1 运行它,然后输入“运行代码”。上面的输出包括“Missing argument”消息,这意味着代码已执行并最终跟随 if (argc
-
终端 > 运行任务...然后选择这个任务,也就是“gcc 构建和调试活动文件”
-
“gcc 构建和调试活动文件”没有出现在我的列表中。出现的最接近的匹配项是“gcc build active file”。
标签: c visual-studio gcc