Похожие чаты

Hey guys, Is it possible to compile a Go program to

a dynamic shared library?
dll extension for Windows and so for Linux I mean.

35 ответов

32 просмотра

why?

Raymond- Автор вопроса
Roman Sharkov
why?

LOL. For many reasons. To be used in a Rust program for example.

Raymond
LOL. For many reasons. To be used in a Rust progra...

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

Raymond- Автор вопроса
Roman Sharkov
what exactly is funny tho? calling Go from another...

Your question was funny man. The reasons of using shared libraries are clear enough.

yes

Raymond- Автор вопроса
Raymond- Автор вопроса
A​kshit
yes

Can explain it? How can I do it?

Roman Sharkov
what exactly is funny tho? calling Go from another...

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

Raymond
Why shouldn't we use it in production?

https://blog.filippo.io/rustgo/ here's an indepth article about it

Raymond
Why shouldn't we use it in production?

its mostly difficult and there are better methods like RPC, APIs or pub-sub queues, etc

Raymond
Can explain it? How can I do it?

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

Anchit
its mostly difficult and there are better methods ...

those are for servers, sometimes you need to go it on the client side for example for a gui application

Roman Sharkov
cgo != Go

not actual C, just exporting go functions for use with C like you do with cgo

A​kshit
those are for servers, sometimes you need to go it...

yes, a GUI application can start two different processes. Those details will be invisible to the user

Raymond- Автор вопроса
Roman Sharkov
https://blog.filippo.io/rustgo/ here's an indepth...

I actually meant 'calling Go from Rust' not 'calling Rust from Go'

Anchit
yes, a GUI application can start two different pro...

which has its own problems 1. shipping another executable 2. IPC is platform dependent

Raymond
I actually meant 'calling Go from Rust' not 'calli...

rust can call C functions and go can expose a C ABI

A​kshit
which has its own problems 1. shipping another exe...

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

Raymond- Автор вопроса
A​kshit
rust can call C functions and go can expose a C AB...

I know how Rust can call C functions. I've already did. Thanks for explaination.

Raymond
I know how Rust can call C functions. I've already...

have you worked with cgo? if yes then you know how to expose a go function to C

Raymond- Автор вопроса
A​kshit
have you worked with cgo? if yes then you know how...

I haven't actually used cgo. I barely know Golang.

Raymond
I haven't actually used cgo. I barely know Golang.

hmmm but i guess that answers your question

Raymond
I actually meant 'calling Go from Rust' not 'calli...

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?

Raymond- Автор вопроса
Roman Sharkov
https://stackoverflow.com/questions/6125683/call-g...

I'm currently learning Go and I thought it would be fun to do it since I already did in other programming languages.

A​kshit
its not that hacky

still, whenever cgo is involved I already start doubting the approach 🙂

Raymond
I'm currently learning Go and I thought it would b...

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

Raymond- Автор вопроса
Roman Sharkov
well, if you're learning Go then why even touch cg...

Why should I avoid it? I always try this when learning a new compiled language and I learn a lot with it.

Raymond- Автор вопроса

Похожие вопросы

Обсуждают сегодня

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
any reference of this implementation?
BitBuddha
29
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Hi guys, any problem with Pulsebrige? Trying to transfer from wETH to ETH. First it tells me to connect my metamask "through mobile app" not desktop. Then I did and confirmed ...
Snowflakecrypto
11
Ⓐrtto, [4/23/24 7:02 PM] Please explain more fully how it is not working exactly, and what are the steps you are taking, and what error messages come or what happens. Ⓐrtto, ...
Ezza Kezza
2
sounds like people have lost their kaspa on tradeogre... does this mean tradeogre not trustworthy?
Ezza Kezza
15
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
11
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
Карта сайта