我从 https://computing.llnl.gov/tutorials/pthreads/ 获得了一些代码,我尝试使用 VSCode 调试器来尝试单步执行它们,但它似乎不起作用。
使用任务(ctrl+shift+B)我可以很好地构建它(我添加了 -pthread 标志),但是当我尝试调试它(F5)时,我收到此错误:
> Executing task: C/C++: gcc build active file <
Starting build...
Build finished with error:
/usr/bin/ld: /tmp/cc5vG56K.o: in function `main':
/home/xristosp59/Documents/Programming/condvar.c:98: undefined reference to `pthread_create'
/usr/bin/ld: /home/xristosp59/Documents/Programming/condvar.c:99: undefined reference to `pthread_create'
/usr/bin/ld: /home/xristosp59/Documents/Programming/condvar.c:100: undefined reference to `pthread_create'
/usr/bin/ld: /home/xristosp59/Documents/Programming/condvar.c:104: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
The terminal process failed to launch (exit code: -1).
我在tasks.json中的不同位置尝试了-pthread和-lpthread标志,但似乎都不起作用,我总是收到此错误。
这是我当前的tasks.json:(这可以很好地构建任务)
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"-pthread",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Generated task by Debugger"
}
],
"version": "2.0.0"
}
如果重要的话,我正在使用 pop_os 20.10。
好吧,显然vscode,当你第一次尝试调试c程序时,它会创建一个launch.json和tasks.json,launch.json有一个
"preLaunchTask": "C/C++: gcc build active file"
选项,tasks.json有一个"label": "C/C++: gcc build active file"
选项,它们匹配,但我猜因为 C/C++: gcc build active file
已经是 vscode 中的一个任务,所以它没有使用任务中的任务(如果我错了,请纠正我)。我更改了两者中的标签,现在它可以工作了。
@xristosp59 我有同样的问题
您可以发布哪些更改?