title: Golang: How to link C objects using CGO_OFILES?
body: <p>I'm pulling my hair out because of this.</p>
  
  <p>All I want to do is link a .o (C object file) with a Go package so the Go package can call the C functions.</p>
  
  <p>There does not appear to be any documentation on <code>CGO_OFILES</code> parameter of cgo, which appears to be what I need after much Internet searching.</p>
  
  <p>I've tried putting this at the top of the Go file:</p>
  
  <pre><code>/*
  #cgo CGO_OFILES: doc-capi-tesseract.o
  #include &lt;stdlib.h&gt;
  #include "doc-capi-tesseract.h"
  */
  import "C"
  </code></pre>
  
  <p>But that gives me the error <code>invalid #cgo verb: #cgo CGO_OFILES: doc-capi-tesseract.o</code>. Then I read somewhere that a makefile can be used, so I made this probably incorrect makefile:</p>
  
  <pre><code>include $(GOROOT)/src/Make.inc
  TARG=tesseract
  CGOFILES=tesseract.go
  CGO_OFILES=doc-capi-tesseract.o
  include $(GOROOT)/src/Make.pkg
  
  %.o: %.cpp
      $(HOST_CC) $(CGO_CFLAGS_$(GOARCH)) -g -O2 -fPIC -o $@ -c $^
  </code></pre>
  
  <p>But I have no idea then what to do with that file. Nothing happens if I run <code>make</code> or <code>make myfile</code> or <code>go build makefile</code>. No idea how to use it.</p>
  
  <p>Could someone please explain to me how to link a Go file to a C object file?</p>