Closed JasonYjz closed 2 years ago
You should install zlib for that arch.
OK, after execute apt-get install libz-dev
, it is ok now.
But there is one query need your help.
Now I need to develop Golang project on Windows, the final actual running envionment is arm64 linux.
My sample project is like below:
When I want to execute go build
command to generate binary,
Jason@LAPTOP-BKD MINGW64 /d/Work/YJZ/Code/aid-mmkv
$ go build
package aid-mmkv
imports tencent.com/mmkv: build constraints exclude all Go files in D:\Work\YJZ\Code\aid-mmkv\my\mmkv
What I need additional configuration steps? Or what build command is effected.
Dev environment setup? That's way out of my reach. You do whatever you like.
I personally prefer dev on the target OS environment instead of daily work environment (in your case Windows). It's can avoid lots of problem. If you don't have a device running the target OS, use a cloud server or a VM.
I personally prefer dev on the target OS environment instead of daily work environment (in your case Windows). It's can avoid lots of problem. If you don't have a device running the target OS, use a cloud server or a VM.
But still cannot run my test code on x86_64 linux after following your suggestion. I directly copy the generated directory(tencent.com) into my project, and execute go run main.go
with the changed go.mod.
[jasyu@manjaro aid-mmkv]$ tree
.
├── go.mod
├── main.go
└── tencent.com
└── mmkv
├── callback.go
├── golang-bridge.cpp
├── golang-bridge.h
├── go.mod
├── lib
│ ├── libcore.a
│ └── libmmkv.a
├── mmkv.go
└── mmkv_test.go
3 directories, 10 files
The errors is below:
[jasyu@manjaro aid-mmkv]$ go install
[jasyu@manjaro aid-mmkv]$ go run main.go
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x4d4e08]
runtime stack:
runtime.throw({0x516cd0?, 0x0?})
/usr/lib/go/src/runtime/panic.go:1047 +0x5d fp=0x7ffd1a2fbe40 sp=0x7ffd1a2fbe10 pc=0x4743bd
runtime.sigpanic()
/usr/lib/go/src/runtime/signal_unix.go:819 +0x369 fp=0x7ffd1a2fbe90 sp=0x7ffd1a2fbe40 pc=0x488529
goroutine 1 [syscall]:
runtime.cgocall(0x4c5100, 0xc00005cee8)
/usr/lib/go/src/runtime/cgocall.go:158 +0x5c fp=0xc00005ceb0 sp=0xc00005ce78 pc=0x4454dc
tencent.com/mmkv._Cfunc_getDefaultMMKV(0x1, {0x0, 0x0})
_cgo_gotypes.go:537 +0x4d fp=0xc00005cee8 sp=0xc00005ceb0 pc=0x4c404d
tencent.com/mmkv.DefaultMMKV()
/home/jasyu/my/aid-mmkv/tencent.com/mmkv/mmkv.go:237 +0x45 fp=0xc00005cf18 sp=0xc00005cee8 pc=0x4c4205
main.main()
/home/jasyu/my/aid-mmkv/main.go:9 +0x1d fp=0xc00005cf80 sp=0xc00005cf18 pc=0x4c47fd
runtime.main()
/usr/lib/go/src/runtime/proc.go:250 +0x212 fp=0xc00005cfe0 sp=0xc00005cf80 pc=0x476c12
runtime.goexit()
/usr/lib/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00005cfe8 sp=0xc00005cfe0 pc=0x49fb41
goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/lib/go/src/runtime/proc.go:363 +0xd6 fp=0xc00004efb0 sp=0xc00004ef90 pc=0x476fd6
runtime.goparkunlock(...)
/usr/lib/go/src/runtime/proc.go:369
runtime.forcegchelper()
/usr/lib/go/src/runtime/proc.go:302 +0xad fp=0xc00004efe0 sp=0xc00004efb0 pc=0x476e6d
runtime.goexit()
/usr/lib/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00004efe8 sp=0xc00004efe0 pc=0x49fb41
created by runtime.init.6
/usr/lib/go/src/runtime/proc.go:290 +0x25
goroutine 3 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/lib/go/src/runtime/proc.go:363 +0xd6 fp=0xc00004f790 sp=0xc00004f770 pc=0x476fd6
runtime.goparkunlock(...)
/usr/lib/go/src/runtime/proc.go:369
runtime.bgsweep(0x0?)
/usr/lib/go/src/runtime/mgcsweep.go:278 +0x8e fp=0xc00004f7c8 sp=0xc00004f790 pc=0x46410e
runtime.gcenable.func1()
/usr/lib/go/src/runtime/mgc.go:178 +0x26 fp=0xc00004f7e0 sp=0xc00004f7c8 pc=0x458fc6
runtime.goexit()
/usr/lib/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00004f7e8 sp=0xc00004f7e0 pc=0x49fb41
created by runtime.gcenable
/usr/lib/go/src/runtime/mgc.go:178 +0x6b
goroutine 4 [GC scavenge wait]:
runtime.gopark(0xc000076000?, 0x52fb28?, 0x1?, 0x0?, 0x0?)
/usr/lib/go/src/runtime/proc.go:363 +0xd6 fp=0xc00004ff70 sp=0xc00004ff50 pc=0x476fd6
runtime.goparkunlock(...)
/usr/lib/go/src/runtime/proc.go:369
runtime.(*scavengerState).park(0x5bbc80)
/usr/lib/go/src/runtime/mgcscavenge.go:389 +0x53 fp=0xc00004ffa0 sp=0xc00004ff70 pc=0x4621b3
runtime.bgscavenge(0x0?)
/usr/lib/go/src/runtime/mgcscavenge.go:617 +0x45 fp=0xc00004ffc8 sp=0xc00004ffa0 pc=0x462785
runtime.gcenable.func2()
/usr/lib/go/src/runtime/mgc.go:179 +0x26 fp=0xc00004ffe0 sp=0xc00004ffc8 pc=0x458f66
runtime.goexit()
/usr/lib/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00004ffe8 sp=0xc00004ffe0 pc=0x49fb41
created by runtime.gcenable
/usr/lib/go/src/runtime/mgc.go:179 +0xaa
goroutine 18 [finalizer wait]:
runtime.gopark(0x5bc080?, 0xc00008a4e0?, 0x0?, 0x0?, 0xc00004e770?)
/usr/lib/go/src/runtime/proc.go:363 +0xd6 fp=0xc00004e628 sp=0xc00004e608 pc=0x476fd6
runtime.goparkunlock(...)
/usr/lib/go/src/runtime/proc.go:369
runtime.runfinq()
/usr/lib/go/src/runtime/mfinal.go:180 +0x10f fp=0xc00004e7e0 sp=0xc00004e628 pc=0x4580cf
runtime.goexit()
/usr/lib/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00004e7e8 sp=0xc00004e7e0 pc=0x49fb41
created by runtime.createfing
/usr/lib/go/src/runtime/mfinal.go:157 +0x45
exit status 2
The code in main.go is similar with the provided test code.
[jasyu@manjaro aid-mmkv]$ cat main.go
package main
import (
"fmt"
"tencent.com/mmkv"
)
func main() {
kv := mmkv.DefaultMMKV()
kv.SetBool(true, "bool")
fmt.Println("bool =", kv.GetBool("bool"))
}
I think my project strcuture is almost same with the 'test' directory, I feel very confused that why not run with my test code. Is this still my envrionmental problem or some additional configration is need?
You have not initialized MMKV. https://github.com/Tencent/MMKV/wiki/golang_setup#configuration
func main() {
// init MMKV with root dir
mmkv.InitializeMMKV("/path/to/your/working/directory")
}
OK. There is one suggestion from my side. I'm not sure whether it is valued.
Whether to wrap this initialization action (mmkv.InitializeMMKV
) in this API (mmkv.DefaultMMKV()
) as well, the default root dir, for example can be set '/tmp/'. If user want to use another dir, can invoke the mmkv.InitializeMMKV
function.
Now that provide mmkv.DefaultMMKV() to create the default MMKV instance, better to do a series of default operations, including intialize root dir.
This is just my simple suggestion, it is up to you.
No. It's a bad idea.
These are totally two different things. DefaultMMKV()
is nothing but a short cut for the more general MMKVWithID()
method. Some may never use the default MMKV instance and stay with their own mmapID.
And setting the working dir to /tmp
is also a really really bad idea. You should never set it to temp in the production code.
I have try to run the MMKV for Golang on arm64 arch platform, not x86. And the both libcore.a and libmmkv.a are successfully compiled to be generated. When I run the test code, it is failed.
Moreover, i have checked this '/usr/lib' folder, the libz.a and libpthread.a are indeed not existed.
My point is how to skip this error, whether there is another workround way to pass the test code.