karalabe / hid

Gopher Interface Devices (USB HID)
Other
263 stars 131 forks source link

Cross compile error in windows #43

Closed lauid closed 1 year ago

lauid commented 1 year ago

this a simple demo code:

package main

import (
    "fmt"
    "time"
    "github.com/karalabe/hid"
)

func main() {
    vid, pid := uint16(0x16C0), uint16(0x05DF)
    devices := hid.Enumerate(vid, pid)
    if len(devices) == 0 {
        fmt.Println("未找到设备")
        return
    }
    device, err := devices[0].Open()
    if err != nil {
        fmt.Println("无法打开设备:", err)
        return
    }
    defer device.Close()

    channel := byte(1)
    state := byte(1) 

    buf := []byte{0x00, 0x00, 0xFF, channel, state}
    _, err = device.Write(buf)
    if err != nil {
        fmt.Println("无法写入数据:", err)
        return
    }

    time.Sleep(1 * time.Second)
}

linux cross compile for window:

CGO_ENABLED=1 GOOS=windows GOARCH=amd64 GOARM= go build -ldflags "-s -w" -o build/relay cmd/relay/main.go

runtime/cgo

gcc: error: unrecognized command line option ‘-mthreads’; did you mean ‘-pthread’? make: *** [Makefile:10: relay] Error 1

windows cross compile for window:

C:\Users\lau\code\demo>mingw32-make.exe CGO_ENABLED=1 GOOS=windows GOARCH=amd64 GOARM= go build -ldflags "-s -w" -o build/relay cmd/relay/main.go

github.com/karalabe/hid

In file included from ........\go\pkg\mod\github.com\karalabe\hid@v1.0.0\hid_enabled.go:40: ........\go\pkg\mod\github.com\karalabe\hid@v1.0.0/hidapi/windows/hid.c: In function 'hid_enumerate': ........\go\pkg\mod\github.com\karalabe\hid@v1.0.0/hidapi/windows/hid.c:431:5: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=] strncpy(cur_dev->path, str, len+1); ^~~~~~~~~~ ........\go\pkg\mod\github.com\karalabe\hid@v1.0.0/hidapi/windows/hid.c:429:11: note: length computed here len = strlen(str); ^~~

How to resolve ? think you