在 clion Ubuntu 中使用 GCC 编译器编译 c++ 文件时出现的问题

在 clion Ubuntu 中使用 GCC 编译器编译 c++ 文件时出现的问题

当我将工具链中的 clion 编译器更改为 gcc-7 或 gcc 时,它会给我对简单的 hello world 程序中所有内容的未定义引用。这是我的代码:

#include <bits/stdtr1c++.h>
using namespace std;
int main()
{
    cout << "hello world\n";
    return 0;
}

这是构建结果:

====================[ Build | training | Debug ]================================
/opt/clion-2019.2.1/bin/cmake/linux/bin/cmake --build /home/saad/CLionProjects/training/cmake-build-debug --target training -- -j 2
Scanning dependencies of target training
[ 50%] Building CXX object CMakeFiles/training.dir/main.cpp.o
[100%] Linking CXX executable training
CMakeFiles/training.dir/build.make:83: recipe for target 'training' failed
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/training.dir/all' failed
CMakeFiles/training.dir/main.cpp.o: In function `main':
CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/training.dir/rule' failed
Makefile:118: recipe for target 'training' failed
/home/saad/CLionProjects/training/main.cpp:5: undefined reference to `std::cout'
/home/saad/CLionProjects/training/main.cpp:5: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
CMakeFiles/training.dir/main.cpp.o: In function `__static_initialization_and_destruction_0(int, int)':
/usr/include/c++/7/iostream:74: undefined reference to `std::ios_base::Init::Init()'
/usr/include/c++/7/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
make[3]: *** [training] Error 1
make[2]: *** [CMakeFiles/training.dir/all] Error 2
make[1]: *** [CMakeFiles/training.dir/rule] Error 2
make: *** [training] Error 2

我安装了GCC

sudo apt 更新

sudo apt 安装 build-essential

sudo apt 安装 gcc

是否还有其他要求需要下载才能在 ubuntu 上的 clion 中使用 GCC 编译器编译 c++ 程序

相关内容