我想为使用Yocto 2.4.1的交叉编译golang应用程序编写yocto食谱,但是我无法使外部依赖项起作用。
谁能帮我?

current RECIPE_FILE: hello-world_%.bb
LICENSE = "CLOSED"
LIC_FILES_CHKSUM = ""
DESCRIPTION = "Hello world test with golang."

inherit go

COMPATIBLE_MACHINE = "(<machine>)"
DEPENDS = "go-cross-${TARGET_ARCH}"
GO_IMPORT = "hello-world"
SRC_URI = "<git_url>/${GO_IMPORT}.git;branch=${SRCBRANCH};tag=${PV}"
SRCBRANCH = "master"
PV = "0.01"
S = "${WORKDIR}/git"

do_compile() {
  export GOPATH="${WORKDIR}/build"
  export GOARCH="<machine_arch>"
  export GOOS="linux"
  export CGO_ENABLED="0"
  go build src/${GO_IMPORT}/hello-world.go
}

 do_install() {
   install -d "${D}/${bindir}"
   install -m 0755 "${WORKDIR}/build/hello-world" "${D}/${bindir}/hello-world"
 }

RDEPENDS_${PN}-dev += "bash"

此配方仅对内部依赖项有效。但是,如何集成外部依赖项,例如“github.com/golang/protobuf/ptypes”?

PROJECT_FILE:hello-world.go
package main

import (
    "fmt"
    "github.com/golang/protobuf/ptypes"
)

func main() {
    timestamp := ptypes.TimestampNow()
    fmt.Println(timestamp)
}

有谁知道此用例的解决方案?

还是有人知道“深入”可以解决这个问题吗?

最好的祝福

最佳答案

我将go dep用作dep,这是一个示例。最麻烦的是关于代理的问题,在配方中也可以解决:

inherit go

LICENSE = "CLOSED"
LIC_FILES_CHKSUM = ""
DESCRIPTION = "Hello world test with golang."

COMPATIBLE_MACHINE = "(<machine>)"
DEPENDS += "go-dep-native"
GO_LINKSHARED = ""

GO_IMPORT = "<git_url>/hello-world.git"
SRC_URI = "<git_url>/${GO_IMPORT}.git;branch=${SRCBRANCH};tag=${PV}"
SRCBRANCH = "master"

do_compile() {
    export SSH_AUTH_SOCK="${SSH_AUTH_SOCK}"
    export HTTP_PROXY="${HTTP_PROXY}"
    ( cd ${WORKDIR}/build/src/${GO_IMPORT} && dep ensure -v )
}

do_compile[vardepsexclude] += "SSH_AUTH_SOCK HTTP_PROXY"

do_install() {
    install -d "${D}/${bindir}"
    install -m 0755 "${WORKDIR}/bin/<arch>/hello-world" "${D}/${bindir}/hello-world"
}

07-24 21:05