FAQ Database Discussion Community


golang: CGO / clang with sqlite3.c

sqlite3,go,clang,cgo
I would like to compile to arm on osx. With the following command: GOOS=linux GOARCH=arm CGO_ENABLED=1 go build -o foo main.go But I get: runtime/cgo clang: error: argument unused during compilation: '-mno-thumb' I use this package: https://github.com/mattn/go-sqlite3 I tried the hints: https://github.com/mattn/go-sqlite3/issues/106 Thanks for every help :-)...

How to add C files in a subdirectory as part of go build by using pseudo CGO directives?

go,cgo
Per docs, go build with cgo will add any C/C++ files in the root of the package as part of the compilation. Is there a way to make C/C++ files in a given subdirectory to also be part of the compilation as well as the ones in the root by...

CGO converting Xlib XEvent struct to byte array?

c,go,xlib,cgo
I am creating a simple window manager (code based of the c code in tinywm) in Golang. To use Xlib, I am using cgo, so my header is: // #cgo LDFLAGS: -lX11 // #include <X11/Xlib.h> And I have a variable declaration, like: event := C.XEvent{} And then, I use this...

Why cgo's performance is so slow? is there something wrong with my testing code?

c,performance,go,cgo
I'm doing a test: compare excecution times of cgo and pure Go functions run 100 million times each. The cgo function takes longer time compared to the golang function, and I am confused with this result. My testing code is: package main import ( "fmt" "time" ) /* #include <stdio.h>...

How to reuse a Go callback in several packages from C?

go,cgo
Is there a way to build a Go + C application that: From main package X, import packages Y and Z. Package M exports a go callback F. Packages X and Y are both built with accompanying C files, both want to call F from C source code. Generally speaking...

cgo: How to pass struct array from c to go

go,cgo
The C part: struct Person {...} struct Person * get_team(int * n) The Go part: n := C.int(0) var team *C.struct_Person = C.get_team(&n) defer C.free(unsafe.Pointer(team)) I can get the first element of the array in this way. But how to get the whole array with n elements? and how to...

Preprocessor flag to detect CGO build?

go,cgo
In a c file that's beside my go file and is compiled together via CGO, I'd like to check via preprocessor whether it's being compiled via go or not. I'd like to do this because, for example, I'd like to protect #include _cgo_export.h with #ifdef flags, since such header exists...

How to use external .c files with CGO?

c,import,go,cgo
To write some C code in a comment above import "C" is straightforward: // foo.go package main /* int fortytwo() { return 42; } */ import "C" import "fmt" func main() { fmt.Printf("forty-two == %d\n", C.fortytwo()) fmt.Printf("forty-three == %d\n", C.fortythree()) } And it works fine: $ go install $ foo...

Why won't my cross-compiled CGO binary run on the Raspberry Pi (Raspbian)?

go,bluetooth,raspberry-pi,raspbian,cgo
When I compile the following snippet of code (playground link): package main /* #cgo LDFLAGS: -lbluetooth #include <bluetooth/bluetooth.h> #include <bluetooth/hci.h> #include <bluetooth/hci_lib.h> */ import "C" func main() { C.hci_get_route(nil) } …using these environment variables: CC=arm-linux-gnueabihf-gcc CGO_ENABLED=1 GOARCH=arm GOARM=6 I get a 1.6Mb binary that: works on my ODROID-C1 (ARMv7, running...