[ c++] cmake 编译时 undefined reference to `std::cout' 错误的解决方案

 

cmake ..  和 make 以后,出现以下错误ios

Linking CXX executable ../../../bin/ModuleTest
CMakeFiles/ModuleTest.dir/tmp.cpp.o: In function `main':
/ModuleTest/tmp.cpp:4: undefined reference to `std::cout'

 

tmp.cpp 内容以下spa

1 #include <iostream>
2 
3 int main(){
4     std::cout << " seconds since the Epoch\n";
5     return 0;
6 }

 

解决方法:code

在 CMakeLists.txt 中添加以下命令,指定 g++ 为编译器。blog

SET(CMAKE_CXX_COMPILER /usr/bin/g++)

 

用 gcc 直接编译会出现一样的错误,用 g++直接编译则不会。编译器

相关文章
相关标签/搜索