Questions tagged [cgo]

Cgo enables the creation of Go packages that call C code.

Cgo enables the creation of Go packages that call C code.

If a Go source file imports "C", it is using cgo. The Go file will have access to anything appearing in the comment immediately preceding the line import "C", and will be linked against all other cgo comments in other Go files, and all C files included in the build process.

Note that there must be no blank lines in between the cgo comment and the import statement.

To access a symbol originating from the C side, use the package name C. That is, if you want to call the C function printf() from Go code, you write C.printf().

It is possible to call both top-level Go functions and function variables from C code invoked from Go code using cgo.

Go makes its functions available to C code through use of a special //export comment. Note: you can't define any C functions in preamble if you're using exports.

Source:https://github.com/golang/go/wiki/cgo

846 questions
-3
votes
1 answer

cc1.exe: sorry, unimplemented: 64-bit mode not compiled in

Error is resolved on Command Prompt Previously, I was receiving this error on Command Prompt, but was resolved by this approach: cc1.exe: sorry, unimplemented: 64-bit mode not compiled in How to resolve error for VS Code debugger Now, VS Code…
Megidd
  • 7,089
  • 6
  • 65
  • 142
-3
votes
1 answer

Is it possible to do configure-make-make install?

I have some Go source files: one.go, two.go,main.go I build them to C static library for using in my cross-platform application compilation. There are 4 types of application compilation: Compilation on Windows Compilation on Ubuntu Compilation on…
test
  • 105
  • 2
  • 8
-3
votes
1 answer

Freeing memory of a cgo library

I'm in a bit of a mess, and I cannot see how I'm getting out of it... What do I got: * A library (dll) I built using cgo. * A c++ app using this library (dll). What do I do: I try to free memory I have allocated in the cgo library in the c++…
Liron Levy
  • 41
  • 1
  • 7
-4
votes
2 answers

Does C Code enjoy the Go GC's fragmentation prevention strategies?

Corrected the false implications: Golang's GC does virtual address space defragmentation fragmentation-prevention strategies, which enables a program to run for a very long time (if not ever). But it seems C code (cgo or SWIG) has no means of having…
Small Boy
  • 147
  • 1
  • 8
-6
votes
1 answer

How to avoid stack overflow in golang?

I have problem with calling function multiple times in go exported to dll. Calling it e.g 80 000 times cause stack overflow. Is there any way to avoid it? Can i clear stack or heap after function call? //export GetNum func GetNum(DeviceType uint32,…
Frnk Wdl
  • 146
  • 2
  • 11
1 2 3
56
57