【发布时间】:2020-10-27 10:50:53
【问题描述】:
我从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。
【问题讨论】:
-
尝试显式链接
pthread库(即添加-lpthread参数)。 -
正如我所说我也尝试过 -lpthread,我现在重试只是为了确保但我仍然得到同样的错误
-
图书馆的顺序很重要。您是否放置了
-lpthread选项last? -
@Someprogrammerdude 是的
-
不仅作为最后一个选项,而且在文件名之后?
标签: c visual-studio-code gdb pthreads vscode-debugger