Issue
I’m trying to make an android executable (not APK) with C bindings in Go. Here are my variables:
set GOARCHarm
set GOOSlinux
set CGO_ENABLED1
set CCC:\ndk\bin\arm-linux-androideabi-gcc
set CGO_LDFLAGS-s -fPIE -pie -rdynamic -Wall -lstdc++ -lbinder -lutils -landroid_runtime -Lbin -linvoke
go build main.go
However when I tried to compile it with the settings above, it gives me:
# runtime/cgo
c:/ndk/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status
After reading a bit about pthread
on android, it says that pthread
lib does not exists in android. How to overcome this? Thanks.
Solution
Android does not have a libpthread
, but the libc
contains a partial pthread implementation. You can use GOOSandroid
to build the application with the correct ld
flags.
Answered By – JimB