报错问题的解决

606 阅读2分钟
  • 环境:Linux / VS Code
  • 语言:C 语言

uint8 undefined

  • 原因:自己typedef了类型但是单独的文件里面没有include进去
  • 解决:可以直接改成uint8_t,也可以把typedef的段复制进.c文件里面,prefer latter

start debugging 后 xx does not exist

  • 原因:在launch.json中配置了"program"参数的路径是当前打开的文档的目录,而不是workspacefolder,所以要在打开想要编译的文件后再debug
  • 解决:打开想要编译的文件后再debug

编译后报错 undefined reference to

  • 原因:编译时在task.json中的“args"中没有包含要引用的头文件
  • 解决:添加.c文件与其对应的路径
  • 参考 blog.csdn.net/u013163834/…

在修改上述报错后仍然出现The PrelaunchTask ‘g++‘ terminated with exit code -1的报错问题

  • 原因:tasks.json 中 tasks 的 label 项必须和 launch.json 的 preLaunchTask 相对应
  • 解决:在launch.json中的preLaunchTask改成和tasks.json 中 tasks 的 label 项一样即可
  • 参考 blog.csdn.net/weixin_4077…
总结
  • 一,vscode中调用外部函数必须修改配置文件的头文件来源
  • 二,编译器的选择要在task.json和launch.json中一致
"-g",
"/home/mydoc/myprog/hello.c",
"-g",
"/home/mydoc/myprog/MyTask.c",

Linux 下 undefined reference to ‘某标准库函数’ 问题解决

已经include了标准库头文件,也添加了编译路径,但仍然报错undefined reference to

  • 原因:pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,需要链接该库。
  • 解决:在编译中要加 -lpthread参数
gcc thread.c -o thread -lpthread

thread.c为你写的源文件,不要忘了加上头文件

#include<pthread.h>

配置文件有问题

  • 原因:多半是task.json的路径的问题
  • 解决:看多复制几遍
    以后两个配置文件launch注意修改args的路径,task注意修改args路径,然后对照label对不对的上。

使用cJson 报错:cJSON.c:  undefined reference to `pow',

  • 原因:因为没有链接动态库
  • 解决:编译加一个-lm即可