0

不幸的是,我不得不硬盘崩溃,不得不重新安装我的 Linux。我尝试将 vs studio 代码与 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;
}` 
4

1 回答 1

0

Blockquote 如果您正在编译 C++,您需要将编译器调用为 g++ 而不是 gcc。否则,它会与 C 运行时库链接,从而导致您看到未定义的符号错误。– 通用汽车 17 分钟前

就是这样!谢谢!真是一团糟,当你以正确的方式做事的那一刻,它突然就起作用了。

于 2021-06-11T09:17:03.030 回答