问题描述
错误信息如下
/usr/bin/ld: CMakeFiles/flow_server.dir/reactor/Reactor_demo.cpp.o: in function `main':
/tmp/cpp_flow_server/reactor/Reactor_demo.cpp:106: multiple definition of `main'; CMakeFiles/flow_server.dir/main.cpp.o:/tmp/cpp_flow_server/main.cpp:38: first defined here
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/flow_server.dir/build.make:145: flow_server] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:83: CMakeFiles/flow_server.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/flow_server.dir/rule] Error 2
gmake: *** [Makefile:124: flow_server] Error 2
我们主要看这一行即可
/tmp/cpp_flow_server/reactor/Reactor_demo.cpp:106: multiple definition of `main'; CMakeFiles/flow_server.dir/main.cpp.o:/tmp/cpp_flow_server/main.cpp:38: first defined here
意思是 /tmp/cpp_flow_server/reactor/Reactor_demo.cpp
文件的106行里面有个main函数,而/tmp/cpp_flow_server/main.cpp
的38行也有个main函数,一个项目中不能同时有2个main函数,属于是重复定义了;
经过查看,确实是有2个main函数,
第一个main函数:
第二个main函数:
解决方案
想要解决这个问题很简单,只需要注释掉其中一个main函数即可,删掉也行
然后点击main.cpp里面的绿色三角形;
构建过程中也没有报错
顺利运行起来了