使用了# include <stdatomic.h>头文件后用gcc 编译报了如下错误:
/usr/lib/gcc/x86_64-linux-gnu/4.9/include/stdatomic.h:40:9: error: ‘_Atomic’ does not name a type
typedef _Atomic _Bool atomic_bool;
用了网上的方法没法解决,后面想到android10源码也使用了一个头文件。
但是andorid10使用的是clang++ 编译的。于是我将vscode 配置成clang++ 编译,就能正常运行了。
配置如下:
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/include"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "clang++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: clang++ 生成活动文件",
"miDebuggerPath": "/usr/bin/gdb" //这里要找到自己的llvm路径
}
]
}
settings.json
{
"files.associations": {
"ostream": "cpp",
"iostream": "cpp",
"typeinfo": "cpp",
"*.tcc": "cpp",
"fstream": "cpp",
"new": "cpp",
"sstream": "cpp"
}
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ 生成活动文件",
"command": "/usr/bin/clang++",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-g",
"${workspaceFolder}/*.cpp",
"-I",
"${workspaceFolder}/include",
"-o",
"${workspaceFolder}/logcat",
"-std=c++11"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}