use*_*879 4 c visual-studio-code
源代码非常简单。
#include <signal.h>
void main() {
sigset_t set;
}
Run Code Online (Sandbox Code Playgroud)
signal.h 已包含在应定义 sigset_t 的位置中。但是vscode还是报问题。
identifier "sigset_t" is undefined
Run Code Online (Sandbox Code Playgroud)
配置文件如下。
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++98",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}
Run Code Online (Sandbox Code Playgroud)
并且程序可以成功编译,没有错误。为什么vscode会报这个错误?
这里的问题是sigset_t只有定义了才被_POSIX_C_SOURCE定义。
gcc 默认使用的 C 标准_POSIX_C_SOURCE已经定义。因此使用 gcc 编译程序不会产生错误。
要解决此问题,您可以添加"cStandard": "gnu11"到配置文件中,或添加"defines": ["_POSIX_C_SOURCE=199309L"].
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++98",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}
Run Code Online (Sandbox Code Playgroud)