title: undefined reference to `main' error in gcc 4.7
body: <p>I created a program in C and I tried to compile it. When I use my gcc 4.8.1 compiler in Widows everything worked and my program too.</p>
  
  <p>I compiled with the following arguments:</p>
  
  <pre><code>gcc -std=c99 -O2 -DCONTEST -s -static -lm children.c
  </code></pre>
  
  <p>But in linux I getting the following error:</p>
  
  <pre><code>/usr/lib/gcc/i486-linux-gnu/4.7/../../../i386-linux-gnu/crt1.o: In function `_start':
  (.text+0x18): undefined reference to `main'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>Why is that? My programm is working and I can't understand why I getting compiling errors in linux.</p>
  
  <p>My code is:</p>
  
  <pre><code>/*---------------------*/
  /* included files      */
  /*---------------------*/
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  /*---------------------*/
  /* defined constants   */
  /* for restriction     */
  /*---------------------*/
  #define MIN 1
  #define MAX 1000000
  #define IOERROR 5   // 'Input/Output Error'
  
  /*---------------------*/
  /* function prototypes */
  /*---------------------*/
  int main();
  FILE *read_input(const char *filename_r);
  int count_children(FILE *input);
  int pass_heights(FILE *input, int *children, int size);
  int check_tall(const int *children, int size);
  void write_output(const int total,const char *filename_w);
  
  
  /*---------------------*/
  /* start of program    */
  /*---------------------*/
  int main() {
  
      const char *filename_r = "xxx.in";
      const char *filename_w = "xxx.out";
  
      FILE *input = read_input(filename_r);
  
      int size = count_children(input);
  
      int *children = malloc(size * sizeof *children);
      if (children==NULL)
      exit(1); //General application error
  
      pass_heights(input, children, size);
  
      fclose(input);
  
      int total = check_tall(children, size);
  
      free(children);
  
      write_output(total,filename_w);
  
      return 0;
  }
  
  FILE *read_input(const char *filename_r) {
  
      FILE *input = fopen(filename_r, "r");
  
      if(input == NULL)
      exit(IOERROR);
  
      return input;
  }
  
  
  int count_children(FILE *input) {
  
      int count = 0;
      fscanf(input, "%d",&amp;count);
  
      if(count &gt; MAX || count &lt; MIN)
      exit(1); //General application error
  
      return count;
  }
  
  
  int pass_heights(FILE *input, int *children, int size) {
  
      for(int i = 0; i &lt; size; i++)
      fscanf(input, "%d",&amp;children[i]);
  
      return *children;
  }
  
  
  int check_tall(const int *children, int size) {
  
      int total = 0;
      int tmp_max = 0;
      for(int i = size - 1; i &gt;= 0; i--)
      {
          if(children[i] &gt; tmp_max) {
              tmp_max = children[i];
              total++;
          }
      }
      return total;
  }
  
  
  void write_output(const int total,const char *filename_w) {
  
      FILE *output = fopen(filename_w, "w");
  
      if(output == NULL)
      exit(IOERROR); 
  
      fprintf(output, "%d\n", total);
      fclose(output);
  }
  </code></pre>