Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make build command failed to compile gopacket package #3074

Closed
shiqinfeng1 opened this issue Oct 21, 2023 · 11 comments
Closed

make build command failed to compile gopacket package #3074

shiqinfeng1 opened this issue Oct 21, 2023 · 11 comments

Comments

@shiqinfeng1
Copy link

shiqinfeng1 commented Oct 21, 2023

gf的版本:

[user@www gopkt]$ gf version
GoFrame CLI Tool v2.5.4, https://goframe.org
GoFrame Version: v1.16.9 in current go.mod
CLI Installed At: /home/user/go/bin/gf
CLI Built Detail:
  Go Version:  go1.20.8
  GF Version:  v2.5.4
  Git Commit:  2023-09-12 22:00:35 5219c5c37ed755ff5f717d6ec07c7a1951453991
  Build Time:  2023-09-12 22:17:31

现象:
代码中引用了gopacket包,使用makebuild命令编译,会编译失败:

[user@www gopkt]$ make build
2023-10-21 21:42:33.408 gf pack resource,manifest internal/packed/build_pack_data.go --keepPath=true
path 'internal/packed/build_pack_data.go' is not empty, files might be overwrote, continue? [y/n]: 
2023-10-21 21:42:34.696 done!
2023-10-21 21:42:34.701 start building...
2023-10-21 21:42:34.701 go build -o ./temp/v2.0.0/linux_amd64/goPktToolv2 main.go
2023-10-21 21:42:34.904 failed to build, os:linux, arch:amd64, error:
# github.com/google/gopacket/pcap
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:30:22: undefined: pcapErrorNotActivated
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:52:17: undefined: pcapTPtr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:64:10: undefined: pcapPkthdr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:103:6: undefined: pcapBpfProgram
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:110:7: undefined: pcapPkthdr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:268:33: undefined: pcapErrorActivated
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:269:33: undefined: pcapWarningPromisc
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:270:33: undefined: pcapErrorNoSuchDevice
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:271:33: undefined: pcapErrorDenied
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:748:14: undefined: pcapTPtr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:271:33: too many errors

you may use command option "--debug" to enable debug info and check the details

make: *** [build] Error 1

cconfig.yaml配置为:

  build:
    name:     "goPktToolv2"
    arch:     "amd64"
    system:   "linux"
    mod:      "none"
    packSrc:  "resource,manifest"
    version:  "v2.0.0"
    extra:    ""

如果直接使用命令执行编译:go build -o ./temp/v2.0.0/linux_amd64/goPktToolv2 main.go ,就可以编译成功。

补充:
编译失败的文件中带有:
// +build !windows

@Issues-translate-bot Issues-translate-bot changed the title make build命令编译 gopacket包失败 make build command failed to compile gopacket package Oct 21, 2023
@gqcn
Copy link
Member

gqcn commented Oct 23, 2023

@shiqinfeng1 It seems that the command make build used different go env from the one of current terminal profile. You can add dumpEnv configuration to the hack.yaml and see the go env used in make build in terminal output.

@gqcn gqcn added the question label Oct 23, 2023
@shiqinfeng1
Copy link
Author

@gqcn This is output info, but it looks no problem?

[user@www gopkt]$ gf build --dumpEnv --debug
+--------------+----------------------------------------------------------+
| GO111MODULE  | ""                                                       |
| GOARCH       | "amd64"                                                  |
| GOBIN        | "/home/user/go/bin"                                      |
| GOCACHE      | "/home/user/.cache/go-build"                             |
| GOENV        | "/home/user/.config/go/env"                              |
| GOEXE        | ""                                                       |
| GOEXPERIMENT | ""                                                       |
| GOFLAGS      | ""                                                       |
| GOHOSTARCH   | "amd64"                                                  |
| GOHOSTOS     | "linux"                                                  |
| GOINSECURE   | "www.jzgit.com"                                          |
| GOMODCACHE   | "/home/user/go/pkg/mod"                                  |
| GONOPROXY    | "www.jzgit.com"                                          |
| GONOSUMDB    | "www.jzgit.com"                                          |
| GOOS         | "linux"                                                  |
| GOPATH       | "/home/user/go"                                          |
| GOPRIVATE    | "www.jzgit.com"                                          |
| GOPROXY      | "https://goproxy.io"                                     |
| GOROOT       | "/usr/local/go"                                          |
| GOSUMDB      | "sum.golang.org"                                         |
| GOTMPDIR     | ""                                                       |
| GOTOOLDIR    | "/usr/local/go/pkg/tool/linux_amd64"                     |
| GOVCS        | ""                                                       |
| GOVERSION    | "go1.20.2"                                               |
| GCCGO        | "gccgo"                                                  |
| GOAMD64      | "v1"                                                     |
| AR           | "ar"                                                     |
| CC           | "gcc"                                                    |
| CXX          | "g++"                                                    |
| CGO_ENABLED  | "1"                                                      |
| GOMOD        | "/home/user/workspace/goPktToolv2/gopkt/go.mod"          |
| GOWORK       | "/home/user/workspace/goPktToolv2/go.work"               |
| CGO_CFLAGS   | "-O2 -g"                                                 |
| CGO_CPPFLAGS | ""                                                       |
| CGO_CXXFLAGS | "-O2 -g"                                                 |
| CGO_FFLAGS   | "-O2 -g"                                                 |
| CGO_LDFLAGS  | "-O2 -g"                                                 |
| PKG_CONFIG   | "pkg-config"                                             |
| GOGCCFLAGS   | "-fPIC -m64 -pthread                                     |
|              | -Wl,--no-gc-sections -fmessage-length=0                  |
|              | -fdebug-prefix-map=/tmp/go-build2185654424=/tmp/go-build |
|              | -gno-record-gcc-switches"                                |
+--------------+----------------------------------------------------------+

2023-10-23 20:44:08.518 [DEBU] build command input: {Meta:{} File: Name:goPktToolv2 Version:v2.0.0 Arch:amd64 System:linux Output: Path:./temp Extra: Mod:none Cgo:false VarMap:map[] PackSrc:resource,manifest PackDst:internal/packed/build_pack_data.go ExitWhenError:false DumpENV:true}
2023-10-23 20:44:08.518 gf pack resource,manifest internal/packed/build_pack_data.go --keepPath=true
path 'internal/packed/build_pack_data.go' is not empty, files might be overwrote, continue? [y/n]: y
2023-10-23 20:44:10.121 done!
2023-10-23 20:44:10.126 [DEBU] git log -1 --format="%cd %H" --date=format:"%Y-%m-%d %H:%M:%S"
2023-10-23 20:44:10.126 start building...
2023-10-23 20:44:10.126 [DEBU] go build -o ./temp/v2.0.0/linux_amd64/goPktToolv2 -ldflags "-X 'github.com/gogf/gf/v2/os/gbuild.builtInVarStr=eyJidWlsdEdpdCI6IiIsImJ1aWx0VGltZSI6IjIwMjMtMTAtMjMgMjA6NDQ6MTAiLCJidWlsdFZlcnNpb24iOiJ2Mi4wLjAifQ=='" main.go
2023-10-23 20:44:10.126 go build -o ./temp/v2.0.0/linux_amd64/goPktToolv2 main.go
2023-10-23 20:44:10.333 failed to build, os:linux, arch:amd64, error:
# github.com/google/gopacket/pcap
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:30:22: undefined: pcapErrorNotActivated
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:52:17: undefined: pcapTPtr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:64:10: undefined: pcapPkthdr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:103:6: undefined: pcapBpfProgram
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:110:7: undefined: pcapPkthdr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:268:33: undefined: pcapErrorActivated
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:269:33: undefined: pcapWarningPromisc
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:270:33: undefined: pcapErrorNoSuchDevice
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:271:33: undefined: pcapErrorDenied
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:748:14: undefined: pcapTPtr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:271:33: too many errors

you may use command option "--debug" to enable debug info and check the details

2023-10-23 20:44:10.334 done!

@hailaz hailaz added the bug It is confirmed a bug, but don't worry, we'll handle it. label Nov 13, 2023
@hailaz
Copy link
Member

hailaz commented Nov 13, 2023

centos 复现,直接build正常,gf build报错
使用gf build --debug -cgo=1开启cgo即可
使用输出的go build -o ./temp/v2.0.0/linux_amd64/goPktToolv2 -ldflags "-X 'github.com/gogf/gf/v2/os/gbuild.builtInVarStr=eyJidWlsdEdpdCI6IjIwMjMtMDctMTIgMTE6Mzc6MTQgOTEyODUwNzQ2OGJiNjU4OGFjODk2YWEzODIyOWI2ZDgwYmZmYWI4MiIsImJ1aWx0VGltZSI6IjIwMjMtMTEtMTMgMTc6MTI6MTMifQ=='" main.go构建也正常

$ gf build --debug
2023-11-13 17:12:13.992 [DEBU] build input: {Meta:{} File: Name:goPktToolv2 Version:v2.0.0 Arch:amd64 System:linux Output: Path:./temp Extra: Mod:none Cgo:false VarMap:map[] PackSrc: PackDst:internal/packed/build_pack_data.go ExitWhenError:false DumpENV:false}
2023-11-13 17:12:13.995 [DEBU] git log -1 --format="%cd %H" --date=format:"%Y-%m-%d %H:%M:%S"
2023-11-13 17:12:13.995 start building...
2023-11-13 17:12:13.995 [DEBU] go build -o ./temp/v2.0.0/linux_amd64/goPktToolv2 -ldflags "-X 'github.com/gogf/gf/v2/os/gbuild.builtInVarStr=eyJidWlsdEdpdCI6IjIwMjMtMDctMTIgMTE6Mzc6MTQgOTEyODUwNzQ2OGJiNjU4OGFjODk2YWEzODIyOWI2ZDgwYmZmYWI4MiIsImJ1aWx0VGltZSI6IjIwMjMtMTEtMTMgMTc6MTI6MTMifQ=='" main.go
2023-11-13 17:12:13.995 go build -o ./temp/v2.0.0/linux_amd64/goPktToolv2 main.go
2023-11-13 17:12:14.083 failed to build, os:linux, arch:amd64, error:
# github.com/google/gopacket/pcap
../../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:30:22: undefined: pcapErrorNotActivated
../../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:52:17: undefined: pcapTPtr
../../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:64:10: undefined: pcapPkthdr
../../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:103:6: undefined: pcapBpfProgram
../../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:110:7: undefined: pcapPkthdr
../../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:268:33: undefined: pcapErrorActivated
../../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:269:33: undefined: pcapWarningPromisc
../../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:270:33: undefined: pcapErrorNoSuchDevice
../../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:271:33: undefined: pcapErrorDenied
../../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:748:14: undefined: pcapTPtr
../../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:271:33: too many errors

you may use command option "--debug" to enable debug info and check the details

2023-11-13 17:12:14.083 done!

复现代码

安装依赖

yum install libpcap-devel

目录结构

.
├── hack
│   └── config.yaml
└── main.go

1 directory, 2 files

配置

gfcli:
  build:
    name: 'goPktToolv2'
    arch: 'amd64'
    system: 'linux'
    mod: 'none'
    # packSrc: 'resource,manifest'
    version: 'v2.0.0'
    extra: ''
    # cgo: true

源码

package main

import (
	"fmt"
	"log"

	"github.com/google/gopacket/pcap"
)

func main() {
	// 得到所有的(网络)设备
	devices, err := pcap.FindAllDevs()
	if err != nil {
		log.Fatal(err)
	}
	// 打印设备信息
	fmt.Println("Devices found:")
	for _, device := range devices {
		fmt.Println("\nName: ", device.Name)
		fmt.Println("Description: ", device.Description)
		fmt.Println("Devices addresses: ", device.Description)
		for _, address := range device.Addresses {
			fmt.Println("- IP address: ", address.IP)
			fmt.Println("- Subnet mask: ", address.Netmask)
		}
	}
}

@github-actions github-actions bot removed the inactive label Nov 13, 2023
hailaz added a commit that referenced this issue Nov 13, 2023
@hailaz
Copy link
Member

hailaz commented Nov 13, 2023

在Windows下交叉编译也会出现同样的问题,用go build不会。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


The same problem will occur when cross-compiling under Windows, but not when using go build.

@hailaz
Copy link
Member

hailaz commented Nov 13, 2023

gcc加交叉编译比较麻烦。需要配合CC、CXX 、CGO_LDFLAGS 有空再研究
golang/go#40129

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


It is more troublesome to add cross compilation with gcc. Need to cooperate with CC, CXX, CGO_LDFLAGS and study again when you have time
golang/go#40129

@hailaz
Copy link
Member

hailaz commented Nov 13, 2023

@gqcn This is output info, but it looks no problem?

[user@www gopkt]$ gf build --dumpEnv --debug
+--------------+----------------------------------------------------------+
| GO111MODULE  | ""                                                       |
| GOARCH       | "amd64"                                                  |
| GOBIN        | "/home/user/go/bin"                                      |
| GOCACHE      | "/home/user/.cache/go-build"                             |
| GOENV        | "/home/user/.config/go/env"                              |
| GOEXE        | ""                                                       |
| GOEXPERIMENT | ""                                                       |
| GOFLAGS      | ""                                                       |
| GOHOSTARCH   | "amd64"                                                  |
| GOHOSTOS     | "linux"                                                  |
| GOINSECURE   | "www.jzgit.com"                                          |
| GOMODCACHE   | "/home/user/go/pkg/mod"                                  |
| GONOPROXY    | "www.jzgit.com"                                          |
| GONOSUMDB    | "www.jzgit.com"                                          |
| GOOS         | "linux"                                                  |
| GOPATH       | "/home/user/go"                                          |
| GOPRIVATE    | "www.jzgit.com"                                          |
| GOPROXY      | "https://goproxy.io"                                     |
| GOROOT       | "/usr/local/go"                                          |
| GOSUMDB      | "sum.golang.org"                                         |
| GOTMPDIR     | ""                                                       |
| GOTOOLDIR    | "/usr/local/go/pkg/tool/linux_amd64"                     |
| GOVCS        | ""                                                       |
| GOVERSION    | "go1.20.2"                                               |
| GCCGO        | "gccgo"                                                  |
| GOAMD64      | "v1"                                                     |
| AR           | "ar"                                                     |
| CC           | "gcc"                                                    |
| CXX          | "g++"                                                    |
| CGO_ENABLED  | "1"                                                      |
| GOMOD        | "/home/user/workspace/goPktToolv2/gopkt/go.mod"          |
| GOWORK       | "/home/user/workspace/goPktToolv2/go.work"               |
| CGO_CFLAGS   | "-O2 -g"                                                 |
| CGO_CPPFLAGS | ""                                                       |
| CGO_CXXFLAGS | "-O2 -g"                                                 |
| CGO_FFLAGS   | "-O2 -g"                                                 |
| CGO_LDFLAGS  | "-O2 -g"                                                 |
| PKG_CONFIG   | "pkg-config"                                             |
| GOGCCFLAGS   | "-fPIC -m64 -pthread                                     |
|              | -Wl,--no-gc-sections -fmessage-length=0                  |
|              | -fdebug-prefix-map=/tmp/go-build2185654424=/tmp/go-build |
|              | -gno-record-gcc-switches"                                |
+--------------+----------------------------------------------------------+

2023-10-23 20:44:08.518 [DEBU] build command input: {Meta:{} File: Name:goPktToolv2 Version:v2.0.0 Arch:amd64 System:linux Output: Path:./temp Extra: Mod:none Cgo:false VarMap:map[] PackSrc:resource,manifest PackDst:internal/packed/build_pack_data.go ExitWhenError:false DumpENV:true}
2023-10-23 20:44:08.518 gf pack resource,manifest internal/packed/build_pack_data.go --keepPath=true
path 'internal/packed/build_pack_data.go' is not empty, files might be overwrote, continue? [y/n]: y
2023-10-23 20:44:10.121 done!
2023-10-23 20:44:10.126 [DEBU] git log -1 --format="%cd %H" --date=format:"%Y-%m-%d %H:%M:%S"
2023-10-23 20:44:10.126 start building...
2023-10-23 20:44:10.126 [DEBU] go build -o ./temp/v2.0.0/linux_amd64/goPktToolv2 -ldflags "-X 'github.com/gogf/gf/v2/os/gbuild.builtInVarStr=eyJidWlsdEdpdCI6IiIsImJ1aWx0VGltZSI6IjIwMjMtMTAtMjMgMjA6NDQ6MTAiLCJidWlsdFZlcnNpb24iOiJ2Mi4wLjAifQ=='" main.go
2023-10-23 20:44:10.126 go build -o ./temp/v2.0.0/linux_amd64/goPktToolv2 main.go
2023-10-23 20:44:10.333 failed to build, os:linux, arch:amd64, error:
# github.com/google/gopacket/pcap
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:30:22: undefined: pcapErrorNotActivated
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:52:17: undefined: pcapTPtr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:64:10: undefined: pcapPkthdr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:103:6: undefined: pcapBpfProgram
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:110:7: undefined: pcapPkthdr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:268:33: undefined: pcapErrorActivated
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:269:33: undefined: pcapWarningPromisc
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:270:33: undefined: pcapErrorNoSuchDevice
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:271:33: undefined: pcapErrorDenied
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:748:14: undefined: pcapTPtr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:271:33: too many errors

you may use command option "--debug" to enable debug info and check the details

2023-10-23 20:44:10.334 done!

@shiqinfeng1
如果是非交叉编译可以先试试gf build --debug -cgo=1,否则就是CGO_ENABLED=1在gf build中失效了。

@hailaz
Copy link
Member

hailaz commented Nov 14, 2023

gcc加交叉编译比较麻烦。需要配合CC、CXX 、CGO_LDFLAGS 有空再研究 golang/go#40129

放弃了,在windows下开启cgo的情况,没法玩。
https://kcsie.github.io/zh-cn/posts/18-go-cross-compile/

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Cross-compiling with gcc is troublesome. Need to cooperate with CC, CXX, CGO_LDFLAGS and study it when you have time golang/go#40129

I gave up and couldn't play it when cgo was turned on under windows.
https://kcsie.github.io/zh-cn/posts/18-go-cross-compile/

@hailaz hailaz removed the bug It is confirmed a bug, but don't worry, we'll handle it. label Nov 14, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2023
@shiqinfeng1
Copy link
Author

@gqcn This is output info, but it looks no problem?

[user@www gopkt]$ gf build --dumpEnv --debug
+--------------+----------------------------------------------------------+
| GO111MODULE  | ""                                                       |
| GOARCH       | "amd64"                                                  |
| GOBIN        | "/home/user/go/bin"                                      |
| GOCACHE      | "/home/user/.cache/go-build"                             |
| GOENV        | "/home/user/.config/go/env"                              |
| GOEXE        | ""                                                       |
| GOEXPERIMENT | ""                                                       |
| GOFLAGS      | ""                                                       |
| GOHOSTARCH   | "amd64"                                                  |
| GOHOSTOS     | "linux"                                                  |
| GOINSECURE   | "www.jzgit.com"                                          |
| GOMODCACHE   | "/home/user/go/pkg/mod"                                  |
| GONOPROXY    | "www.jzgit.com"                                          |
| GONOSUMDB    | "www.jzgit.com"                                          |
| GOOS         | "linux"                                                  |
| GOPATH       | "/home/user/go"                                          |
| GOPRIVATE    | "www.jzgit.com"                                          |
| GOPROXY      | "https://goproxy.io"                                     |
| GOROOT       | "/usr/local/go"                                          |
| GOSUMDB      | "sum.golang.org"                                         |
| GOTMPDIR     | ""                                                       |
| GOTOOLDIR    | "/usr/local/go/pkg/tool/linux_amd64"                     |
| GOVCS        | ""                                                       |
| GOVERSION    | "go1.20.2"                                               |
| GCCGO        | "gccgo"                                                  |
| GOAMD64      | "v1"                                                     |
| AR           | "ar"                                                     |
| CC           | "gcc"                                                    |
| CXX          | "g++"                                                    |
| CGO_ENABLED  | "1"                                                      |
| GOMOD        | "/home/user/workspace/goPktToolv2/gopkt/go.mod"          |
| GOWORK       | "/home/user/workspace/goPktToolv2/go.work"               |
| CGO_CFLAGS   | "-O2 -g"                                                 |
| CGO_CPPFLAGS | ""                                                       |
| CGO_CXXFLAGS | "-O2 -g"                                                 |
| CGO_FFLAGS   | "-O2 -g"                                                 |
| CGO_LDFLAGS  | "-O2 -g"                                                 |
| PKG_CONFIG   | "pkg-config"                                             |
| GOGCCFLAGS   | "-fPIC -m64 -pthread                                     |
|              | -Wl,--no-gc-sections -fmessage-length=0                  |
|              | -fdebug-prefix-map=/tmp/go-build2185654424=/tmp/go-build |
|              | -gno-record-gcc-switches"                                |
+--------------+----------------------------------------------------------+

2023-10-23 20:44:08.518 [DEBU] build command input: {Meta:{} File: Name:goPktToolv2 Version:v2.0.0 Arch:amd64 System:linux Output: Path:./temp Extra: Mod:none Cgo:false VarMap:map[] PackSrc:resource,manifest PackDst:internal/packed/build_pack_data.go ExitWhenError:false DumpENV:true}
2023-10-23 20:44:08.518 gf pack resource,manifest internal/packed/build_pack_data.go --keepPath=true
path 'internal/packed/build_pack_data.go' is not empty, files might be overwrote, continue? [y/n]: y
2023-10-23 20:44:10.121 done!
2023-10-23 20:44:10.126 [DEBU] git log -1 --format="%cd %H" --date=format:"%Y-%m-%d %H:%M:%S"
2023-10-23 20:44:10.126 start building...
2023-10-23 20:44:10.126 [DEBU] go build -o ./temp/v2.0.0/linux_amd64/goPktToolv2 -ldflags "-X 'github.com/gogf/gf/v2/os/gbuild.builtInVarStr=eyJidWlsdEdpdCI6IiIsImJ1aWx0VGltZSI6IjIwMjMtMTAtMjMgMjA6NDQ6MTAiLCJidWlsdFZlcnNpb24iOiJ2Mi4wLjAifQ=='" main.go
2023-10-23 20:44:10.126 go build -o ./temp/v2.0.0/linux_amd64/goPktToolv2 main.go
2023-10-23 20:44:10.333 failed to build, os:linux, arch:amd64, error:
# github.com/google/gopacket/pcap
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:30:22: undefined: pcapErrorNotActivated
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:52:17: undefined: pcapTPtr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:64:10: undefined: pcapPkthdr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:103:6: undefined: pcapBpfProgram
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:110:7: undefined: pcapPkthdr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:268:33: undefined: pcapErrorActivated
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:269:33: undefined: pcapWarningPromisc
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:270:33: undefined: pcapErrorNoSuchDevice
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:271:33: undefined: pcapErrorDenied
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:748:14: undefined: pcapTPtr
../../../go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:271:33: too many errors

you may use command option "--debug" to enable debug info and check the details

2023-10-23 20:44:10.334 done!

@shiqinfeng1 如果是非交叉编译可以先试试gf build --debug -cgo=1,否则就是CGO_ENABLED=1在gf build中失效了。

命令gf build --debug -cgo=1在linux环境下,编译windows和linux版本都可以编译通过。不加-cgo=1的情况下,在linux下可以 编译成功win版本, 编译linux版本报错。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants