a dynamic shared library?
dll extension for Windows and so for Linux I mean.
why?
LOL. For many reasons. To be used in a Rust program for example.
what exactly is funny tho? calling Go from another language is near impossible (there are very hacky ways but you shouldn't do it in production) IPC is preferable
Your question was funny man. The reasons of using shared libraries are clear enough.
yes
Why shouldn't we use it in production?
Can explain it? How can I do it?
its not hacky at all :) you can literally use cgo exports and build with buildtype=c-shared or c-archive. then use the resulting dll / archive
https://blog.filippo.io/rustgo/ here's an indepth article about it
its mostly difficult and there are better methods like RPC, APIs or pub-sub queues, etc
1. you need cgo exports (please google this), and you need to compile with cgo enabled 2. build with buildmode=c-shared or c-archive and link it with anything. it will work with stuff that supports calling C functions
those are for servers, sometimes you need to go it on the client side for example for a gui application
not actual C, just exporting go functions for use with C like you do with cgo
yes, a GUI application can start two different processes. Those details will be invisible to the user
I actually meant 'calling Go from Rust' not 'calling Rust from Go'
which has its own problems 1. shipping another executable 2. IPC is platform dependent
rust can call C functions and go can expose a C ABI
youre already shipping two files, a dynamic lib and an executable. why not ship two bins and something to start both (one in the background) insteadf
I know how Rust can call C functions. I've already did. Thanks for explaination.
build as c-archive and statically link
have you worked with cgo? if yes then you know how to expose a go function to C
I haven't actually used cgo. I barely know Golang.
hmmm but i guess that answers your question
https://stackoverflow.com/questions/6125683/call-go-functions-from-c according to my personal experience it's really hacky and you should try to avoid it. what's the reason you want non-Go code to call Go?
its not that hacky
I'm currently learning Go and I thought it would be fun to do it since I already did in other programming languages.
still, whenever cgo is involved I already start doubting the approach 🙂
well, if you're learning Go then why even touch cgo in the first place? 😅 https://dave.cheney.net/2016/01/18/cgo-is-not-go
also this, don't touch cgo if possible
Why should I avoid it? I always try this when learning a new compiled language and I learn a lot with it.
read the article, it's a great read 🙂
Ofc. Thanks for sharing.
Обсуждают сегодня