Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instruction for cross-compilation #78

Open
FedeBev opened this issue Oct 30, 2020 · 1 comment
Open

Instruction for cross-compilation #78

FedeBev opened this issue Oct 30, 2020 · 1 comment

Comments

@FedeBev
Copy link

FedeBev commented Oct 30, 2020

Hi there,

I'm trying to cross-compile from linux with OSX as target but I get the following error

building for OS darwin ARCH amd64
# github.com/keybase/go-keychain
../../../go/pkg/mod/github.com/keybase/go-keychain@v0.0.0-20190712205309-48d3d31d256d/corefoundation_1.10.go:9:10: fatal error: 'CoreFoundation/CoreFoundation.h' file not found
#include <CoreFoundation/CoreFoundation.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
# net
/usr/local/go/src/net/cgo_bsd.go:15:72: could not determine kind of name for C.AI_MASK
# os/user
/usr/local/go/src/os/user/getgrouplist_darwin.go:16:11: warning: implicit declaration of function 'getgrouplist' is invalid in C99 [-Wimplicit-function-declaration]

I saw the issue #23 but I don't understand how the PR #20 could fix this issue, that PR "just" add cgo build tag

What I have tried

I've tried the following build commands:

  • GOOS=darwin GOARCH=amd64 go build works without building keychain
  • GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build doesn't work, fail withe the above error
  • CC=clang-11 GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build doesn't work, fails with the above error
  • CC=clang-11 CXX=clang++-11 GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build doesn't work, faisl with the above error

Build environment

go version:

go version go1.15.3 linux/amd64

keyring module version

github.com/99designs/keyring v1.1.6

clang-11 --version:

Ubuntu clang version 11.0.0-++20201008094836+176249bd673-1~exp1~20201008080315.114
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

clang++-11 --version:

Ubuntu clang version 11.0.0-++20201008094836+176249bd673-1~exp1~20201008080315.114
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

OS version (lsb_release -a):

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.5 LTS
Release:	18.04
Codename:	bionic
@osok
Copy link

osok commented Jun 29, 2021

I have part of this solved for you, but I'm here in the issues section to comment on a compile error which could be related to my environment setup. None the less this will get you further along. That error is because golang cannot find the xcode libraries with swift. So you need to install swift then tell go where the libraries and header files are.

I was using ubuntu 20.04, but you should be able to switch out the swift library for 18.04.

so you need

apt-get install -yq wget git build-essential 
apt-get install -yq libpython2.7 libpython2.7-dev
apt-get install -yq llvm libicu-dev clang 

wget -c https://swift.org/builds/swift-5.4.2-release/ubuntu2004/swift-5.4.2-RELEASE/swift-5.4.2-RELEASE-ubuntu20.04.tar.gz
tar -xvf swift-5.4.2-RELEASE-ubuntu20.04.tar.gz
mv swift-5.4.2-RELEASE-ubuntu20.04 /usr/share/swift
export PATH=/usr/local/go/bin:/usr/share/swift/usr/bin:$PATH


GOARCH=amd64
CGO_ENABLED=1
GOOS=darwin
CXX=clang++
CC=clang
CGO_CFLAGS=-I/usr/share/swift/usr/lib/swift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants