wow. that .go got mangled by copy and paste. 2nd attempt: package main
/* #cgo LDFLAGS: -ldl #include <dlfcn.h> #include <stdlib.h> #include <stdio.h> // 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(int a, int b) { void* handle = dlopen("./libexample.so", RTLD_LAZY); if (!handle) { fprintf(stderr, "Error loading library: %s\n", dlerror()); return -1; } // not C, but you'll need the moral equivalent of // defer dlclose(handle); // to clean up. multiply_func multiply = (multiply_func)dlsym(handle, "multiply"); if (!multiply) { fprintf(stderr, "Error finding function: %s\n", dlerror()); return -1; } return multiply(a, b); } */ import "C" import "fmt" func main() { // Call the C function through our wrapper result := C.call_multiply(C.int(5), C.int(7)) if result == -1 { fmt.Println("Error calling multiply function") return } fmt.Printf("5 * 7 = %d\n", int(result)) } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/0f94b67d-a7c9-413d-8696-6fef8d2eea62n%40googlegroups.com.