Advertisement
AntonioVillanueva

Cargando librerias dinamicas de c en go

Apr 26th, 2023 (edited)
1,087
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.56 KB | None | 0 0
  1. package main
  2.  
  3. /*
  4. // #cgo LDFLAGS: -L. -lmylib
  5. #include "mylib.h"
  6. */
  7. import "C"
  8. import "fmt"
  9.  
  10. func main() {
  11.     // Llamar a la función "my_function" con los parámetros necesarios
  12.     arg1 := C.int(10)
  13.     arg2 := C.int(11)
  14.     ret := C.my_function(arg1, arg2)
  15.  
  16.     fmt.Printf("Resultado: %d\n", int(ret))
  17. }
  18. /*
  19.  
  20. mylib.h
  21. #ifndef MYLIB_H
  22. #define MYLIB_H
  23.  
  24. int my_function(int arg1, int arg2);
  25.  
  26. #endif
  27.  
  28.  
  29. mylib.c
  30. #include "mylib.h"
  31.  
  32. int my_function(int arg1, int arg2){
  33.     return arg1+arg2;
  34. }
  35.  
  36. La libreria asi compilada asi gcc -shared -o mylib.so mylib.c
  37.  
  38.  
  39. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement