Closed honey-yogurt closed 2 years ago
@zhiguogg 说明encoding/json.Unmarshal在你的loader里不存在这个符号,如果你的loader里没有调用过这个函数,那么需要调用goloader.RegTypes来完成注册,具体可以看examples
The JIT compiler in #66 will be able to import and build external packages for you automatically, so you don't have to register types on the loader side anymore.
See the tests in jit/jit_test.go
for examples
You can simply do:
loadable, err = jit.BuildGoFiles(jit.BuildConfig{}, "./path/to/file1.go", "/path/to/file2.go")
// or
loadable, err = jit.BuildGoPackage(jit.BuildConfig{}, "./path/to/package")
// or
loadable, err = jit.BuildGoText(jit.BuildConfig{}, `
package mypackage
import "encoding/json"
func MyFunc(input []byte) (interface{}, error) {
var output interface{}
err := json.Unmarshal(input, &output)
return output, err
}
`)
if err != nil {
panic(err)
}
module, symbols, err = loadable.Load()
if err != nil {
panic(err)
}
MyFunc := symbols["MyFunc"].(func([]byte) (interface{}, error))
执行 ./loader -o hello.o -run main.Hello会报错:
Load error: unresolve external:encoding/json.Unmarshal
但是可以进行序列化