cmake编译时undefinedreferenceto`std::cout'错误的解决方案
作者:三味书屋 来源: 2022/6/22 8:39:10

C++代码如下:


#include <cstdlib>
#include <iostream>
#include <string>

std::string say_hello()
{
	return std::string("hello word!");
}
int main(int argc,char** argv)
{
	std::cout<<say_hello()<<std::endl;
	return EXIT_SUCCESS;
}


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

CMakeList.txt内容如下:


cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(hello-world-01 LANGUAGES CXX)

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

add_executable(hello-world hello-world.cpp)


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


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


称      呼:
联系方式:
您的评论:
技术支持:l.w.dong@qq.com www.luweidong.cn
广州市   wx:lwdred
Copyright © 2014 三味书屋 All Rights Reserved
技术支持:l.w.dong@qq.com  sitemap xml  sitemap html

粤公网安备44010602011869号

粤ICP备13031080号-1