Thanks Jason, I was looking for something like that indeed :)
However meanwhile I found an amazing Go package that does what I want
https://github.com/rainycape/dl
He does the same as you do with some assembly and automatic type conversion
with reflect package to facilitate user experience :)
wow. that .go got mangled by copy and paste. 2nd attempt:
package main
/*
#cgo LDFLAGS: -ldl
#include
#include
#include
// Define the function type that matches our C function
typedef int (*multiply_func)(int, int);
// Helper function to load and call the multiply function
int call_multiply(
Below is a working example in C. Once you have
that going, then add the CGO layer on top to call from Go.
Note I seem to recall you might have to mark your C function as //extern
...maybe, if
in a separate C file and not inline in the .go file... read the CGO docs
in full for details.
$ cat libe
You can not directly call a C function pointer from Go. You will need a CGO
wrapper that calls it and them you call that wrapper from Go.
-Bruno
On Thu, May 15, 2025, 5:20 AM rudeus greyrat
wrote:
> Hello,
>
> Thanks for your answer.
>
> Three points to note:
>
>- I never asked how to crea
Hello,
Thanks for your answer.
Three points to note:
- I never asked how to create an so, I already have a given so :/
- No need to provide the code because the issue is simple to describe: I
have an address of a function in a Go variable, how to call it ?
- AI is garbage (even thou
On Wed, May 14, 2025 at 4:17 PM rudeus greyrat
wrote:
> I am still a beginner in Linux internals so please bear with me.
>
> I have a ".so" that export "helloworld" function.
>
> I load the ".so" using CGO by:
>
>1. Creating a file descriptor
>2. using ```write``` to write the so to it
>
I am still a beginner in Linux internals so please bear with me.
I have a ".so" that export "helloworld" function.
I load the ".so" using CGO by:
1. Creating a file descriptor
2. using ```write``` to write the so to it
3. Get a handle using ```dlopen```
4. Get the address of ```hello