title: calling assembly function from c
body: <p>I'm trying to call an assembly function from c,but i keep getting errors.</p>
  
  <pre><code>    .text
      .globl integrate
      .type integrate, @function
  integrate:
      push %ebp
      mov %esp, %ebp
      mov $0,%edi
  start_loop:                
      cmp %edi,1024           
      je loop_exit
      mov 8(%ebp),%eax          
      mov 12(%ebp),%ecx          
      sub %eax,%ecx              
      add %edi,%ecx
      incl %edi                
      jmp start_loop             
  loop_exit:                 
      movl %ebp, %esp
      popl %ebp
      ret   
  </code></pre>
  
  <p>This is my assembly function,file called integrate.s.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  extern int integrate(int from,int to);
  
  void main()
  {
      printf("%d",integrate(1,10));
  }
  </code></pre>
  
  <p>Heres my c code.</p>
  
  <pre><code>function.c:5:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
  /tmp/cciR63og.o: In function `main':
  function.c:(.text+0x19): undefined reference to `integrate'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>Whenever i try to compile my code with gcc -Wall function.c -o function,it gives the 'undefined reference to integrate' error.I also tried adding link to the integrate.s file from c,like </p>
  
  <pre><code>#include&lt;(file path)/integrate.s&gt;
  </code></pre>
  
  <p>but it didnt work as well.Btw what assembly code is doing is not important,for now im just trying to call the function from c successfully.Can anyone help me about solving this problem ?</p>