cross-compilation Error
geeksmy opened this issue · 4 comments
geeksmy commented
Hi, I cross-compile windows and linux executable files under mac os, and use makefile to report an error
makefile
# workdir info
PACKAGE=scan
PREFIX=$(shell pwd)
CMD_PACKAGE=${PACKAGE}
OUTPUT_DIR=${PREFIX}/bin
OUTPUT_FILE=${OUTPUT_DIR}/scan
COMMIT_ID=$(shell git rev-parse --short HEAD)
VERSION=$(shell git describe --tags || echo "v0.0.0")
VERSION_IMPORT_PATH=github.com/lneoe/go-help-libs/version
BUILD_TIME=$(shell date '+%Y-%m-%dT%H:%M:%S%Z')
VCS_BRANCH=$(shell git symbolic-ref --short -q HEAD)
# which golint
GOLINT=$(shell which golangci-lint || echo '')
# build args
BUILD_ARGS := \
-ldflags "-X $(VERSION_IMPORT_PATH).appName=$(PACKAGE) \
-X $(VERSION_IMPORT_PATH).version=$(VERSION) \
-X $(VERSION_IMPORT_PATH).revision=$(COMMIT_ID) \
-X $(VERSION_IMPORT_PATH).branch=$(VCS_BRANCH) \
-X $(VERSION_IMPORT_PATH).buildDate=$(BUILD_TIME)"
EXTRA_BUILD_ARGS=
.PONY: lint test
default: lint test build
all: clean setup build-windows build-linux build-mac
lint:
@echo "+ $@"
@$(if $(GOLINT), , \
$(error Please install golint: `go get -u github.com/golangci/golangci-lint/cmd/golangci-lint`))
golangci-lint run --deadline=10m --disable-all -E errcheck ./...
test:
@echo "+ test"
go test -cover $(EXTRA_BUILD_ARGS) ./...
build:
@echo "+ build"
go build $(BUILD_ARGS) $(EXTRA_BUILD_ARGS) -o ${OUTPUT_FILE} $(CMD_PACKAGE)
setup:
mkdir -p bin/linux
mkdir -p bin/osx
mkdir -p bin/windows
build-windows: setup
CGO_ENABLED=0 GOARCH=amd64 GOOS=windows go build $(BUILD_ARGS) $(EXTRA_BUILD_ARGS) -o bin/windows/${PACKAGE}.exe $(CMD_PACKAGE)
build-linux: setup
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build $(BUILD_ARGS) $(EXTRA_BUILD_ARGS) -o bin/linux/${PACKAGE} $(CMD_PACKAGE)
build-mac: setup
CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build $(BUILD_ARGS) $(EXTRA_BUILD_ARGS) -o bin/osx/${PACKAGE} $(CMD_PACKAGE)
clean:
@echo "+ $@"
@rm -r "${OUTPUT_DIR}"
Error message
+ clean
mkdir -p bin/linux
mkdir -p bin/osx
mkdir -p bin/windows
CGO_ENABLED=0 GOARCH=amd64 GOOS=windows go build -ldflags "-X github.com/lneoe/go-help-libs/version.appName=scan -X github.com/lneoe/go-help-libs/version.version=v0.0.1-5-g82dbcbc -X github.com/lneoe/go-help-libs/version.revision=82dbcbc -X github.com/lneoe/go-help-libs/version.branch=dev/Web-fingerprint -X github.com/lneoe/go-help-libs/version.buildDate=2021-03-20T10:04:17CST" -o bin/windows/scan.exe scan
# github.com/mattn/go-oci8
../../../.gvm/pkgsets/go1.15.6/global/pkg/mod/github.com/mattn/go-oci8@v0.1.1/connector.go:14:10: undefined: Connector
../../../.gvm/pkgsets/go1.15.6/global/pkg/mod/github.com/mattn/go-oci8@v0.1.1/connector.go:20:18: undefined: Connector
../../../.gvm/pkgsets/go1.15.6/global/pkg/mod/github.com/mattn/go-oci8@v0.1.1/connector.go:21:9: undefined: Driver
../../../.gvm/pkgsets/go1.15.6/global/pkg/mod/github.com/mattn/go-oci8@v0.1.1/connector.go:25:18: undefined: Connector
../../../.gvm/pkgsets/go1.15.6/global/pkg/mod/github.com/mattn/go-oci8@v0.1.1/connector.go:30:11: undefined: Conn
make: *** [build-windows] Error 2
MichaelS11 commented
Did you look at the other issues that are similar to this? If so, what did you find?
geeksmy commented
I've seen the same problem with the "github.com/gijsbers/go-pcre" library, which seems to be the cause of system dependence
MichaelS11 commented
Did you go through the readme file again?
MichaelS11 commented
All good? Can this be closed?