C Linking Error: undefined reference to 'main'

前端 未结 4 1576
走了就别回头了
走了就别回头了 2021-02-06 22:50

I have read the other answers on this topic, and unfortunately they have not helped me. I am attempting to link several c programs together, and I am getting an error in respons

4条回答
  •  礼貌的吻别
    2021-02-06 23:12

    Generally you compile most .c files in the following way:

    gcc foo.c -o foo. It might vary depending on what #includes you used or if you have any external .h files. Generally, when you have a C file, it looks somewhat like the following:

    #include 
        /* any other includes, prototypes, struct delcarations... */
        int main(){
        */ code */
    }
    

    When I get an 'undefined reference to main', it usually means that I have a .c file that does not have int main() in the file. If you first learned java, this is an understandable manner of confusion since in Java, your code usually looks like the following:

    //any import statements you have
    public class Foo{
        int main(){}
     }
    

    I would advise looking to see if you have int main() at the top.

提交回复
热议问题