I'm pulling my hair out because of this.
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.
There does not appear to be any documentation on CGO_OFILES
parameter of cgo, which appears to be what I need after much Internet searching.
I've tried putting this at the top of the Go file:
/*
#cgo CGO_OFILES: doc-capi-tesseract.o
#include <stdlib.h>
#include "doc-capi-tesseract.h"
*/
import "C"
But that gives me the error invalid #cgo verb: #cgo CGO_OFILES: doc-capi-tesseract.o
. Then I read somewhere that a makefile can be used, so I made this probably incorrect makefile:
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 $^
But I have no idea then what to do with that file. Nothing happens if I run make
or make myfile
or go build makefile
. No idea how to use it.
Could someone please explain to me how to link a Go file to a C object file?
Example to #2:
// #cgo CFLAGS: -Isrc/include
// Where doc-capi-tesseract.h is!
// #cgo LDFLAGS: doc-capi-tesseract.a
// #include "doc-capi-tesseract.h"
import "C"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With