title: Problem linking an Assembly (AT&T) file with C program using GCC
body: <p>I have my C program in 'main.c' and a function called list_equal() in 'list_equal.c'.</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include "main.h"
  
  int list_equal(const node_t *l1, const node_t *l2) {
      while (l1!=NULL &amp;&amp; l2!=NULL) {
          if (l1-&gt;elem != l2-&gt;elem) return 0;
          l1 = l1-&gt;next;
          l2 = l2-&gt;next;
      }
      return l1==NULL &amp;&amp; l2==NULL;
  }
  </code></pre>
  
  <p>When I compile my program using: </p>
  
  <pre><code>$ gcc -m32 main.c list_equal.c -o main
  </code></pre>
  
  <p>everything worked fine and I was able to run my program './main'.</p>
  
  <p>Then I translated my function in assembly code using AT&amp;T syntax and named it "list_equal.s". Here's the code. </p>
  
  <pre><code>.globl list_equal
  
  list_equal:
  
  movl 4(%esp),%eax
  movl 8(%esp),%ecx
  
  L:
  
  testl %eax,%eax
  jz E
  testl %ecx,%ecx
  jz E
  movw (%ecx),%dx
  cmpw %dx,(%eax)
  je F
  movl $0,%eax
  ret
  
  E:
  
  testl %eax,%eax
  setz %al
  testl %ecx,%ecx
  setz %ah
  andb %ah,%al
  movsbl %al,%eax
  ret
  
  F:
  
  movl 4(%eax),%eax
  movl 4(%ecx),%ecx
  jmp L
  </code></pre>
  
  <p>But when I try to compile my program again, this time using the assembly 'list_equal.s', with the command:</p>
  
  <pre><code>$gcc -m32 main.c list_equal.s -o main
  </code></pre>
  
  <p>I get this error message:</p>
  
  <pre><code>Undefined symbols for architecture i386:
    "_list_equal", referenced from:
        _test in main-bbda7f.o
  ld: symbol(s) not found for architecture i386
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>Thank you in advance.</p>
  
  <p>Informations about my gcc compiler:</p>
  
  <pre><code>$ gcc --version
  Configured with: --prefix=/Applications/Xcode_9.4.1.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
  Apple LLVM version 9.1.0 (clang-902.0.39.2)
  Target: x86_64-apple-darwin18.6.0
  Thread model: posix
  InstalledDir: /Applications/Xcode_9.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
  </code></pre>