karalabe / xgo

Go CGO cross compiler
MIT License
2.14k stars 280 forks source link

C-Shared buildmode for Android #159

Open dcam0050 opened 5 years ago

dcam0050 commented 5 years ago

I've been trying to compile a simple c-shared library for android but cannot seem to get it to work.

This is the code I'm trying to compile:

package main

import "fmt"

func main() {}

//export Test
func Test(){
    fmt.Print("Hello android")
}

This is the command I'm running: xgo --targets=android/arm --buildmode=c-shared -out android_test ./test

To which I get the following:

Checking docker installation...
Client:
 Version:           18.09.6
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        481bc77
 Built:             Sat May  4 02:35:57 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.6
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.8
  Git commit:       481bc77
  Built:            Sat May  4 01:59:36 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Checking for required docker image karalabe/xgo-1.12... found.
Cross compiling github.com/test...
Building locally github.com/test...
Assembling toolchain for android-16/arm...
Bootstrapping android-16/arm...
Compiling for android-16/arm...
# github.com/test
/usr/local/go/pkg/tool/linux_amd64/link: running arm-linux-androideabi-gcc failed: exit status 1
/usr/arm-linux-androideabi-4.9/bin/../sysroot/usr/lib/crtbegin_dynamic.o:crtbrand.c:function _start: error: undefined reference to 'main'
collect2: error: ld returned 1 exit status

Any idea as to what is wrong? And thank you for a great tool!

ZoneTong commented 5 years ago

me too!!!when i compile android on macbook pro, report error:

# github.com/ZoneTong/yunxingningmeng
/usr/local/go/pkg/tool/linux_amd64/link: running arm-linux-androideabi-gcc failed: exit status 1
/usr/arm-linux-androideabi-4.9/bin/../sysroot/usr/lib/crtbegin_dynamic.o:crtbrand.c:function _start: error: undefined reference to 'main'
collect2: error: ld returned 1 exit status

2019/11/16 23:13:00 Failed to cross compile package: exit status 2.
make: *** [so] Error 1
jeronimo13 commented 4 years ago

Sorry to bring that up, but any ideas on how to fix it or why this did it happen?