Golang for external dynamic libraries - has anyone used this ?

Has anyone compiled external dynamic libraries (dll, so / dylib) built from golang and used them via declare statements inside a Xojo program on Windows, Mac and Linux GUI / cross platform Console programs ?

I’ve previously only done this in C but golang appears to have some very nice looking libraries which makes the language attractive for backend library type work.

Specifically the encryption libraries available to golang appear to be pretty good.

Now I know golang works differently to lets say a traditionally compiled library written and compiled with gcc in that it has built in garbage collection and whatever else golang comes with so I wonder if this is an issue or not ?

I suspect it won’t be a problem so I’m going to be running some basic tests on this anyway but I’d like to hear of anyone elses experiences with golang usage with Xojo.

See https://github.com/golang/go/issues/11058
Esp towards the end of the thread in 2016 (recent comments are < 23 hours old)

Thanks, I’m sure this will be helpful (took a quick look already). I need only a single DLL. Will read up on this next week.

Golang seems to be an unstoppable force lately and it’s getting better all the time by the looks of it.

If the powers that be at Google decided to make a cross platform Golang GUI visual IDE then I have a feeling that it could almost be game over for a lot of existing systems but I doubt that will ever happen.

Golang 1.10 was released today or yesterday so I thought I would revisit this topic.

I was able to get a simple function written in Golang built as a Windows DLL and successfully call it from within a Xojo console app having declared it as a function.

Creating the dll using go does require gcc to be installed on the windows dev system.

This was a rough and ready simple first test that outputs a line of text, I will run additional tests in the future as I now look at golang to supplement my programs.

This opens up a whole new world of ‘back end’ functionality with Xojo as a front end.

Simple proof of concept :

64 bit Windows console app run event :

dim retval as integer
soft Declare function HelloWorld Lib "O:\\go\\dlltest\\hello.dll" () as integer
print "After declare"
retval = HelloWorld()
print "After function call to go dll...."


package main

import "fmt"
import "C"

func main(){}
//export HelloWorld
func HelloWorld() int {
fmt.Println("This is output of the function in the golang created dll")
return 0

golang build command

go build -buildmode=c-shared -o hello.dll hello.go

Program output :

O:\\xojo\\dllgolang\\Builds - golangdll.xojo_project\\Windows 64 bit\\golangdll>golangdll
After declare
This is output of the function in the golang created dll
After function call to go dll....

O:\\xojo\\dllgolang\\Builds - golangdll.xojo_project\\Windows 64 bit\\golangdll>

At this most basic level it appears to work just fine, I will be exploring additional options in the future.

I guess things to look out for are which variable types match up, etc. Also - I’ve read that you should never ‘unload’ a golang dll.

I’ve already gone ‘64 bit only’ now which means that I really could do with that 64 bit windows debugger, any word on when we can expect that to be available ?

Anyone tried to do a similar thing with OSX?, I mean make a call to GO from xojo without using a shell?

Seems to all work fine on OSX …


(Only very quickly knocked together and tested with what I’ve got here: 2019r3 on Catalina, with the latest OSX go build: go1.13.5.darwin-amd64)


Thanks Charlie, will take a look.