Well unluky as I am i had to a hard drive crash and had to reinstall my Linux. I tried to use vs studio code with C++20 but he does not recognize it. Below is my config.
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++-10 build active file",
"command": "/usr/bin/g++-10",
"args": [
"-g",
"/home/johannes/Documents/CPP/projects/firstproject/.vscode/main.cpp",
"-o",
"-std=gnu++20",
"/home/johannes/Documents/CPP/projects/firstproject/.vscode/main"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: /bin/g++-10",
}
]
}
i want to make a c++ program with Linux. How do i convince my system to use cpp 20? I installed gcc 10.2 but now I cant compile anything. And my last "__cplusplus" tells me its still using cpp14.
I do appretiate your time and wisdome.
I tried:
gcc -o xxx xx.cpp
and gcc-10 -o xxx xx.cpp
.
/usr/bin/ld: /tmp/ccdWDdXJ.o: warning: relocation against `_ZSt4cout' in read-only section `.text'
/usr/bin/ld: /tmp/ccdWDdXJ.o: in function `main':
Test1.cpp:(.text+0x17): undefined reference to `std::cout'
/usr/bin/ld: Test1.cpp:(.text+0x1c): undefined reference to `std::ostream::operator<<(long)'
/usr/bin/ld: Test1.cpp:(.text+0x26): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/usr/bin/ld: Test1.cpp:(.text+0x31): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/usr/bin/ld: Test1.cpp:(.text+0x3d): undefined reference to `std::cout'
/usr/bin/ld: Test1.cpp:(.text+0x42): undefined reference to `std::ostream::operator<<(unsigned int)'
/usr/bin/ld: Test1.cpp:(.text+0x4c): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/usr/bin/ld: Test1.cpp:(.text+0x57): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/usr/bin/ld: /tmp/ccdWDdXJ.o: in function `__static_initialization_and_destruction_0(int, int)':
Test1.cpp:(.text+0x87): undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: Test1.cpp:(.text+0x9c): undefined reference to `std::ios_base::Init::~Init()'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
</pre>```
My Cppis below here.
`#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
std::cout << __cplusplus << std::endl;
std::cout << (unsigned int)__cplusplus << std::endl;
return 0;
}`
Blockquote If you're compiling C++ you need to invoke the compiler as g++ not gcc. Otherwise it links with the C runtime libraries resulting in the undefined symbol errors you're seeing. – G.M. 17 mins ago
Thats it! Thanks! What a mess, the moment you do it the right way it suddenly works.