MX Linux doesn’t have gcc installed by default
I’ve installed it and now all is good
So now this is the Go code:
package main
import "C"
//export HelloIntro
func HelloIntro(name *C.char) *C.char {
who := C.GoString(name)
return C.CString("Hello " + who)
}
func main() {
// Need a main function to make CGO compile package as C shared library
}
And a PureBasic snippet that calls the resulting library:
Enumeration
#libcgo
EndEnumeration
If Not OpenLibrary(#libcgo, "cgotest.so")
MessageRequester("Error", "Failed to open library", 0)
End
EndIf
*fn = GetFunction(#libcgo, "HelloIntro")
If *fn
*bf = UTF8("Steve")
*rs = CallCFunctionFast(*fn, *bf)
Debug PeekS(*rs, -1, #PB_UTF8)
FreeMemory(*bf)
Else
MessageRequester("Error", "Function not found", 0)
EndIf
CloseLibrary(#libcgo)
I like it
.
.
Edit ( as three consecutive posts are disallowed )
.
.
How would I do the reverse?
Say I had a shared library, libfoo.so, which contained the function hello_intro with the signature:
char* hello_intro(char* s);
How would I call hello_intro from Go?
Silly question what’s the name of the file you save to disk?