sbinet/go-python

Cross compiling for Linux on MacOS fails

dhanush opened this issue · 3 comments

I am trying to cross compile my application from local devbox for linux amd64 environment. I use this command

env CC=x86_64-pc-linux-gcc GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CGO_LDFLAGS="-L/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config -lpython2.7" go build -v -o bin/linux_amd64/app ./src/cmd/main

But the build fails saying

# mydir/vendor/github.com/sbinet/go-python
/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.a: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status

Why is this file format not recognized? Do I need to pass in any other arguments?

you probably need object files for linux for that library.
IIRC, Cellar will contain files for your local OS/arch (ie: darwin/amd64, right?)

you probably need object files for linux for that library.
IIRC, Cellar will contain files for your local OS/arch (ie: darwin/amd64, right?)

Yes. Cellar contains the local OS/arch files. Do we need to have libpython2.7.so file then ?

yes.