Linux Debian 10 如何使用c++ 20

Linux Debian 10 how to use c++ 20

不幸的是,我遇到了硬盘崩溃,不得不重新安装我的 Linux。我尝试将 vs studio code 与 C++20 一起使用,但他无法识别。下面是我的配置。

{
    "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",
            
        }
    ]
}

我想用 Linux 制作一个 C++ 程序。我如何说服我的系统使用 cpp 20?我安装了 gcc 10.2 但现在我无法编译任何东西。我的最后一个“__cplusplus”告诉我它仍在使用 cpp14。 我很感激你的时间和智慧。 我试过了: gcc -o xxx xx.cppgcc-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

就是这样!谢谢!真是一团糟,当你按照正确的方式去做的时候,它突然就起作用了。