码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-07-03 19:16:06      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:let   compiler   class   span   fine   com   iostream   txt   pil   

 

cmake ..  和 make 之后,出现如下错误

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 内容如下

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

 

解决方法:

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

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

 

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

 

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

标签:let   compiler   class   span   fine   com   iostream   txt   pil   

原文地址:http://www.cnblogs.com/TonyYPZhang/p/7112511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!