Compile error: Undefined symbols: “_main”, referenced from: start in crt1.10.5.o

前端 未结 3 1236
既然无缘
既然无缘 2021-02-07 04:06

I have the following code:

#include 

using namespace std;

class testing{
   int test() const;
   int test1(const testing& test2);
};

int t         


        
3条回答
  •  情书的邮戳
    2021-02-07 05:11

    You have tried to link it already:

    g++ file.cpp
    

    That will not only compile it, but try to already create the executable. The linker then is unable to find the main function that it needs. Well, do it like this:

    g++ -c file.cpp
    g++ -c hasmain.cpp
    

    That will create two files file.o and hasmain.o, both only compiled so far. Now you can link them together with g++:

    g++ -omy_program hasmain.o file.o
    

    It will automatically figure out that those are files already compiled, and invoke the linker on them to create a file "my_program" which is your executable.

提交回复
热议问题