我試圖交叉編譯的樹莓派與CGO_ENABLED=1
一個Golang應用程序在編譯過程中,我得到了錯誤:交叉編譯 - 警告:libudev.so.1沒有發現因<code>libusb</code>依賴</p> <p>
arm-linux-gnueabihf/bin/ld: warning: libudev.so.1, needed by /usr/lib/arm-linux-gnueabihf/libusb-1.0.so, not found (try using -rpath or -rpath-link)
我曾嘗試下面的命令的多種變化,沒有運氣:
CGO_ENABLED=1 GOARCH=arm GOARM=7 PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ go build -x -ldflags '-extld=arm-linux-gnueabihf-gcc -rpath=/usr/lib/arm-linux-gnueabihf -L/usr/lib/arm-linux-gnueabihf -ludev'
當我運行與構建標誌我得到了詳細的輸出,它還挺看起來像它的失敗,同時建立src/net
包:
cd /usr/local/go/src/net
/usr/local/go/pkg/tool/linux_amd64/cgo -dynpackage net -dynimport $WORK/net/_obj/_cgo_.o -dynout $WORK/net/_obj/_cgo_import.go
arm-linux-gnueabihf-gcc -I . -fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -o $WORK/net/_obj/_all.o $WORK/net/_obj/_cgo_export.o $WORK/net/_obj/cgo_linux.cgo2.o $WORK/net/_obj/cgo_resnew.cgo2.o $WORK/net/_obj/cgo_socknew.cgo2.o $WORK/net/_obj/cgo_unix.cgo2.o -g -O2 -Wl,-r -nostdlib -Wl,--build-id=none
/usr/local/go/pkg/tool/linux_amd64/compile -o $WORK/net.a -trimpath $WORK -p net -buildid 9e58c94d1ddeba63666a35ecee9409056baf5d3c -D _/usr/local/go/src/net -I $WORK -pack ./addrselect.go ./conf.go ./dial.go ./dnsclient.go ./dnsclient_unix.go ./dnsconfig_unix.go ./dnsmsg.go ./fd_mutex.go ./fd_poll_runtime.go ./fd_posix.go ./fd_unix.go ./file.go ./file_unix.go ./hook.go ./hook_cloexec.go ./hook_unix.go ./hosts.go ./interface.go ./interface_linux.go ./ip.go ./iprawsock.go ./iprawsock_posix.go ./ipsock.go ./ipsock_posix.go ./lookup.go ./lookup_unix.go ./mac.go ./net.go ./nss.go ./parse.go ./pipe.go ./port.go ./port_unix.go ./sendfile_linux.go ./sock_cloexec.go ./sock_linux.go ./sock_posix.go ./sockopt_linux.go ./sockopt_posix.go ./sockoptip_linux.go ./sockoptip_posix.go ./tcpsock.go ./tcpsock_posix.go ./tcpsockopt_posix.go ./tcpsockopt_unix.go ./udpsock.go ./udpsock_posix.go ./unixsock.go ./unixsock_posix.go ./writev_unix.go $WORK/net/_obj/_cgo_gotypes.go $WORK/net/_obj/cgo_linux.cgo1.go $WORK/net/_obj/cgo_resnew.cgo1.go $WORK/net/_obj/cgo_socknew.cgo1.go $WORK/net/_obj/cgo_unix.cgo1.go $WORK/net/_obj/_cgo_import.go
# github.com/resin-io/edge-node-manager/vendor/github.com/kylelemons/gousb/usb
/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: warning: libudev.so.1, needed by /usr/lib/arm-linux-gnueabihf/libusb-1.0.so, not found (try using -rpath or -rpath-link)
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_2.17'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
/usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `[email protected]_183'
collect2: error: ld returned 1 exit status
奇怪的是,編譯器能找到/usr/lib/arm-linux-gnueabihf/libusb-1.0.so
,如果我在那個目錄做ls -al
libudev.so
也存在。鏈接回/lib/arm-linux-gnueabihf/
lrwxrwxrwx 1 root root 41 Jan 7 04:14 libudev.so -> /lib/arm-linux-gnueabihf/libudev.so.1.5.0
-rw-r--r-- 1 root root 105464 Jun 16 2014 libusb-1.0.a
lrwxrwxrwx 1 root root 44 Jun 16 2014 libusb-1.0.so -> /lib/arm-linux-gnueabihf/libusb-1.0.so.0.1.0
drwxr-xr-x 2 root root 4096 Mar 15 14:48 pkgconfig
/usr/lib/arm-linux-gnueabihf/pkgconfig
這兩個文件包含:
-rw-r--r-- 1 root root 513 Jan 7 04:13 libudev.pc
-rw-r--r-- 1 root root 332 Jun 16 2014 libusb-1.0.pc
最後,運行file
同時顯示libusb
和libudev
是正確的架構:
/lib/arm-linux-gnueabihf/libusb-1.0.so.0.1.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=7d7b487c91042c1f254b39516b4aeabedfb828fc, stripped
/lib/arm-linux-gnueabihf/libudev.so.1.5.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=334f4f0d8b1222a324ccd0827c1613fdd1e2ec15, stripped
您是否嘗試過使用'CC_FOR_TARGET'和'CXX_FOR_TARGET'? – JimB
@JimB同樣的錯誤 –
你可以嘗試使用'-x'來確保編譯器調用完全符合預期。 – JimB