登录
首页 >  Golang >  Go问答

无法在 Yocto 中进行交叉编译 GoLang 和 Wails 应用

来源:stackoverflow

时间:2024-02-18 17:36:22 365浏览 收藏

你在学习Golang相关的知识吗?本文《无法在 Yocto 中进行交叉编译 GoLang 和 Wails 应用》,主要介绍的内容就涉及到,如果你想提升自己的开发能力,就不要错过这篇文章,大家要知道编程理论基础和实战操作都是不可或缺的哦!

问题内容

我正在使用 yocto kirkstone 为 armv7 定制嵌入式 linux 板构建系统。我的 yocto 元层中有 go-runtime 版本 1.20。

我正在尝试构建一个简单的示例 golang“wails”(https://github.com/wailsapp/wails)应用程序,我可以在 mac 上为我的目标构建该应用程序。这需要安装 wails 'cli' 来构建应用程序。我不知道如何与 yocto 交叉编译这个应用程序。我怎样才能做到这一点?谢谢。

此命令在 do_compile() 中失败:

wails build .

我收到的错误如下所示:

...
| hash[link github.com/wailsapp/wails/v2/cmd/wails]: "packagefile internal/lazyregexp=pnipfusr6bdvpzrfoo2q\n"
| hash[link github.com/wailsapp/wails/v2/cmd/wails]: 58443e84e42fc0e5254356b82561065095a39a1606a457c34cf63d8dd364173c
| hash subkey a9f4ce5dc6a5c97cab06b5c8cfec3a64e5db0f7bcc79e02fc0002cafcc719a67 "link-stdout" = 80ee6464b934ca7407296396849147804b0862ee25e2b844a6e9cc98cfa588b3
| qemu-arm: could not open '/lib/ld-linux-armhf.so.3': no such file or directory
| warning: /home/sensonix/poky/build-microchip/tmp/work/cortexa5t2hf-neon-vfpv4-poky-linux-gnueabi/go-example/1.0.0-r0/temp/run.do_compile.87405:178 exit 255 from './bin/linux_arm/wails build .'
| warning: backtrace (bb generated script):
|       #1: do_compile, /home/sensonix/poky/build-microchip/tmp/work/cortexa5t2hf-neon-vfpv4-poky-linux-gnueabi/go-example/1.0.0-r0/temp/run.do_compile.87405, line 178
|       #2: main, /home/sensonix/poky/build-microchip/tmp/work/cortexa5t2hf-neon-vfpv4-poky-linux-gnueabi/go-example/1.0.0-r0/temp/run.do_compile.87405, line 186

bitbake 食谱:

DESCRIPTION = "Wails Example App"
LICENSE = "CLOSED"
LIC_FILES_CHKSUM=""

SRC_URI = "file://wails.json"
SRC_URI += "file://README.md"
SRC_URI += "file://main.go"
SRC_URI += "file://app.go"
SRC_URI += "file://frontend"

GO_IMPORT = "import"
GO_LINKSHARED = ""
PTEST_ENABLED="0"
export GO111MODULE="auto"
CGO_ENABLED = "1"

inherit go goarch

do_compile() {

    cd ${WORKDIR}/build
    export TMPDIR="${GOTMPDIR}"

    ${GO} install github.com/wailsapp/wails/v2/cmd/wails@latest

    export GOPATH="$GOPATH:${S}/src/import/.gopath"

    # Pass the needed cflags/ldflags so that cgo
    # can find the needed headers files and libraries
    export CGO_CFLAGS="${CFLAGS} --sysroot=${STAGING_DIR_TARGET}"
    export CGO_LDFLAGS="${LDFLAGS} --sysroot=${STAGING_DIR_TARGET}"

    ./bin/linux_arm/wails build .

    #${GO} build ${GO_LINKSHARED} ${GOBUILDFLAGS} -o streamerapp

    cd ${OLDPWD}

}

do_install() {

    cd ${WORKDIR}/build
    #install -m  SRC DEST

    mkdir -p ${D}${bindir}
    #install -m 0755 ./wailsapp ${D}${bindir}

    cd ${OLDPWD}

}

正确答案


我用下面的方法解决了这个问题。

DESCRIPTION = "Wails Example App"
LICENSE = "CLOSED"
LIC_FILES_CHKSUM=""

LICENSE = "CLOSED"

SRC_URI = "git://[email protected]/abc/go-wails-demo.git;branch=master;protocol=ssh"
SRCREV = "eaa61c30bff997c811da1d176c7273cea4f6b7d8"

GO_IMPORT = "import"
GO_LINKSHARED = ""
PTEST_ENABLED="0"
CGO_ENABLED = "1"

DEPENDS = "nodejs-native"
DEPENDS += "gtk+3 webkitgtk"

INSANE_SKIP:${PN} += "already-stripped"

inherit go goarch pkgconfig

do_compile() {

    # Allow cloning of properietary repositories
    git config --global --add url."[email protected]:".insteadOf "https://github.com/"
    ${GO} env -w GOPRIVATE="github.com/abc"

    cd ${WORKDIR}/go-wails-demo-1.0.0/src/import
    export TMPDIR="${GOTMPDIR}"

    # Pass the needed cflags/ldflags so that cgo
    # can find the needed headers files and libraries
    export QEMU_LD_PREFIX="${STAGING_DIR_TARGET}"
    export GOARCH=${TARGET_GOARCH}
    export CGO_ENABLED="1"
    export CGO_CFLAGS="${CFLAGS} --sysroot=${STAGING_DIR_TARGET}"
    export CGO_LDFLAGS="${LDFLAGS} --sysroot=${STAGING_DIR_TARGET}"
    export GO111MODULE="on"
    export GOPATH="${WORKDIR}/build"
    export GIT_TERMINAL_PROMPT=1

    ${GO} install github.com/wailsapp/wails/v2/cmd/wails@latest

    /usr/bin/sync
    sleep 0.5

    ${WORKDIR}/build/bin/linux_arm/wails build .

}

do_install() {

    cd ${WORKDIR}/go-wails-demo-1.0.0/src/import/build/bin

    mkdir -p ${D}${bindir}
    install -m 0755 ./react-wails-demo ${D}${bindir}

    cd ${OLDPWD}

}

今天关于《无法在 Yocto 中进行交叉编译 GoLang 和 Wails 应用》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>