标签:har load def sign run abort ref com log
|- sample
|- c
|- libsample
|- libsample.h
|- libsample.cpp
|- g
|- main.go
#ifdef __cplusplus
extern "C" {
#endif
int add(int a, int b);
#ifdef __cplusplus
}
#endif
#include "libsample.h"
int add(int a, int b)
{
return a + b;
}
g++ -c libsample.cpp -o libsample.o
ar -crv libsample.a libsample.o
package main
/*
#cgo CFLAGS: -I../c/libsample
#cgo LDFLAGS: -L../c/libsample -lsample
#include "libsample.h"
*/
import "C"
import "fmt"
func main() {
fmt.Println("hello world")
ret := C.add(11, 23)
fmt.Println(ret)
}
$ go run main.go
hello world
34
g++ -fPIC -shared -o libsample.so libsample.cpp
$ go run main.go
dyld: Library not loaded: libsample.so
Referenced from: /var/folders/t0/4pythctd2ygbjp8sprsxp4vh0000gp/T/go-build106945710/b001/exe/main
Reason: image not found
signal: abort trap
标签:har load def sign run abort ref com log
原文地址:https://www.cnblogs.com/edwardorchis/p/10534465.html