g++运行c++程序提示main()找不到

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: error: ld returned 1 exit status

原因:
要编译的c程序test.c可能是“只读型文件”,既不能写,也不能执行,之前对它的写入的程序实际上并没有保存,所以会报main()找不到这个错误
解决办法:
修改test.c的权限(chmod 777 test.c),重新写入程序,再次编译(g++ -c test.c)和生成可执行文件(g++ -o test test.o),最后运行test这个文件(./test),运行成功

原文地址:https://www.cnblogs.com/hi3254014978/p/11875567.html