title: cgo : Undefined symbols for architecture x86_64
body: <p>I would like to call the go func from the C function space, but the program throws the build error.</p>
  
  <p>example.go</p>
  
  <pre><code>package main
  
  /*
  #include "test.c"
  */
  import "C"
  import "fmt"
  
  func Example() {
      fmt.Println("this is go")
      fmt.Println(C.GoString(C.myprint(C.CString("go!!"))))
  }
  
  // export receiveC              (remove the extra space between // and export)
  func receiveC(msg *C.char) {
      fmt.Println(C.GoString(msg))
  }
  
  func main() {
      Example()
  }
  </code></pre>
  
  <p>test.c</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  extern void receiveC(char *msg);
  
  char* myprint(char *msg) {
      receiveC(msg);  // calling the exported go function
      return msg;     
      }
  </code></pre>
  
  <p>When I execute the command to run/build (<code>go build</code> or <code>go run example.go</code> or <code>go build example.go</code>) the program, it throws the error:</p>
  
  <pre><code># github.com/subh007/goodl/cgo
  Undefined symbols for architecture x86_64:
    "_receiveC", referenced from:
        _myprint in example.cgo2.o
        __cgo_6037ec60b2ba_Cfunc_myprint in example.cgo2.o
        _myprint in test.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>I am following the <a href="http://akrennmair.github.io/golang-cgo-slides/#5" rel="nofollow">cgo slides</a> to writing the program. Please let me know for any mistakes here.</p>
  
  <p>Edit1: I am using OS-X 10.9 OS.</p>
  
  <p>Edit2:
  I have one extra space between <code>// export</code>, there should be no space between <code>//</code> and <code>export</code>. But now I am getting the following error while building :</p>
  
  <pre><code># github.com/subh007/goodl/cgo
  duplicate symbol _myprint in:
      $WORK/github.com/subh007/goodl/cgo/_obj/_cgo_export.o
      $WORK/github.com/subh007/goodl/cgo/_obj/example.cgo2.o
  duplicate symbol _receiver_go in:
      $WORK/github.com/subh007/goodl/cgo/_obj/_cgo_export.o
      $WORK/github.com/subh007/goodl/cgo/_obj/example.cgo2.o
  duplicate symbol _myprint in:
      $WORK/github.com/subh007/goodl/cgo/_obj/_cgo_export.o
      $WORK/github.com/subh007/goodl/cgo/_obj/test.o
  duplicate symbol _receiver_go in:
      $WORK/github.com/subh007/goodl/cgo/_obj/_cgo_export.o
      $WORK/github.com/subh007/goodl/cgo/_obj/test.o
  ld: 4 duplicate symbols for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>