gonuts / ffi Goto Github PK
View Code? Open in Web Editor NEWCGo bindings to libffi
CGo bindings to libffi
Hi.
Not sure how this library supporting, but I'm getting troubles calling Rust function from Go.
Here simple Rust function:
use std::thread;
#[no_mangle]
pub extern fn process() {
let handles:Vec<_> = (0..10).map(|_|{
thread::spawn(||{
let mut x = 0;
for _ in 0..5_000_000 {
x += 1
}
x
})
}).collect();
for h in handles {
println!("Thread finished with count={}",
h.join().map_err(|_| "Could not join thread!").unwrap());
}
println!("done!");
}
And I'm calling it as described in an example:
package main
import (
"fmt"
"github.com/gonuts/ffi"
)
func main() {
// dl-open a library: here, the math library on darwin
lib, err := ffi.NewLibrary("libembed.rlib")
// get a handle to 'cos', with the correct signature
cos, err := lib.Fct("process", ffi.C_void, []ffi.Type{})
handle_err(err)
// call it
out := cos(0.).Float()
println("cos(0.)=", out)
err = lib.Close()
handle_err(err)
}
func handle_err(err error) {
if err != nil {
fmt.Println("Error:",err)
}
}
And getting the following error calling go build.
This library does not build with Go 1.14 on macOS:
$ go version
go version go1.14.2 darwin/amd64
$ go get github.com/gonuts/ffi
# github.com/gonuts/ffi
$GOPATH/src/github.com/gonuts/ffi/ffi.go:190:7: cannot take the address of _Cmacro_ffi_type_uint()
$GOPATH/src/github.com/gonuts/ffi/ffi.go:192:7: cannot take the address of _Cmacro_ffi_type_sint()
$GOPATH/src/github.com/gonuts/ffi/type.go:244:50: cannot take the address of _Cmacro_ffi_type_uchar()
$GOPATH/src/github.com/gonuts/ffi/type.go:245:41: cannot take the address of _Cmacro_ffi_type_schar()
$GOPATH/src/github.com/gonuts/ffi/type.go:246:51: cannot take the address of _Cmacro_ffi_type_ushort()
$GOPATH/src/github.com/gonuts/ffi/type.go:247:42: cannot take the address of _Cmacro_ffi_type_sshort()
$GOPATH/src/github.com/gonuts/ffi/type.go:248:49: cannot take the address of _Cmacro_ffi_type_uint()
$GOPATH/src/github.com/gonuts/ffi/type.go:249:40: cannot take the address of _Cmacro_ffi_type_sint()
$GOPATH/src/github.com/gonuts/ffi/type.go:250:50: cannot take the address of _Cmacro_ffi_type_ulong()
$GOPATH/src/github.com/gonuts/ffi/type.go:251:41: cannot take the address of _Cmacro_ffi_type_slong()
$GOPATH/src/github.com/gonuts/ffi/ffi.go:192:7: too many errors
The same build errors were previously reported in #1.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.