I want to switch the c 11 to c 17 in vs code. I tried following instructions, but it didn't work.
tasks.json
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C : g build active file",
"command": "/usr/bin/g ",
"args": [
"-g",
"-Wall",
"-std=c 17",
"${fileDirname}/*.cpp",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/g "
}
]
c_cpp_properties.json
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/g ",
"cStandard": "c11",
"cppStandard": "c 17",
"intelliSenseMode": "${default}"
}
],
"version": 4
launch.json
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g - Build and debug active file",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [
],
"cwd": "${fileDirname}",
"preLaunchTask": "C/C : g build active file"
}
]
settings.json
"C_Cpp.errorSquiggles": "Enabled",
"C_Cpp.default.cppStandard": "c 17",
"files.associations": {
"*html": "html",
"iostream": "cpp",
"iosfwd": "cpp",
"ostream": "cpp",
"istream": "cpp",
"fstream": "cpp",
"new": "cpp",
"__bit_reference": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__functional_base": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__nullptr": "cpp",
"__split_buffer": "cpp",
"__string": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"algorithm": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"cmath": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"functional": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"numeric": "cpp",
"optional": "cpp",
"queue": "cpp",
"ratio": "cpp",
"set": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"utility": "cpp",
"vector": "cpp",
"thread": "cpp"
}
Also changed to c 17 in the C/C Configurations (UI).
I'm having trouble compiling my work due to this issue. Having this warning generated:
Executing task: C/C : g build active file < Starting build... /usr/bin/g -g -Wall -std=c 17 /Users/aziznosirov/Documents/cpp_udemy/btp305_w2_p1/*.cpp -o /Users/aziznosirov/Documents/cpp_udemy/btp305_w2_p1/w2_p1 /Users/aziznosirov/Documents/cpp_udemy/btp305_w2_p1/w2_p1.cpp:43:14: warning: ISO C 11 does not allow conversion from string literal to 'char *' [-Wwritable-strings] t.addEvent(" 0-arg Constructor");
You can see although it says c 17 on the compiler when building, it still generates a warning mentioning c 11.
Any help would be appreciated. Thanks.
CodePudding user response:
Looking at the Build Task
we can see that the code is actually being compiled explicitly with the -std=c 17
flag.
I suspect that the compiler that is being used is not a recent one , GCC -7
had experimental support for C 17 features which could be used by using
-std=c 1z
flag.
Starting GCC 8 , the Compiler had full C 17 support .
I suggest updating the GCC package.
CodePudding user response:
I solved the problem. I just needed to add a const. My c 17 was actually working.