douyi2798
douyi2798
2018-11-09 07:35

尽管我已经安装了libpcap,但遇到“找不到lpcap”错误

已采纳

Facing error with "cannot find lpcap" for make command for some package, although I have already installed libpcap.devel.

go build -i -ldflags "-linkmode external -extldflags -static -X main.version=git-6e3f8a1c7a0a" -tags netgo -o prog/weaver/weaver ./prog/weaver
# github.com/weaveworks/weave/prog/weaver
/go/pkg/tool/linux_s390x/link: running s390x-linux-gnu-gcc failed: exit status 1
/usr/lib64/gcc/s390x-suse-linux/7/../../../../s390x-suse-linux/bin/ld: cannot find -lpcap
/tmp/go-link-225248852/000015.o: In function `mygetgrouplist':
/tmp/workdir/go/src/os/user/getgrouplist_unix.go:15: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

I can see the .so files at

/usr/lib64 # ls | grep pcap

libpcap.so

libpcap.so.1

libpcap.so.1.8.1

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • dqvzfp6468 dqvzfp6468 3年前

    The openSUSE libpcap development RPm does not provide a static libpcap.a, so you cannot statically link libpcap unless you are able to build the static library from source (and any others to which the same applies).

    Removing -static from your -ldflags would avoid this problem, if it is an option for you to link your go program dynamically.

    点赞 评论 复制链接分享
  • drag2458 drag2458 3年前

    Install the devel version of the library and you get the headers and the .a files as well as the .so shared libraries

    The C linker needs these for static linking

    Also, the build process needs to be able to find the .a files. This should happen automatically but you can help it

    Find the directory that the .a files are in ( for instance by listing the package you used to install ) and add that directory with a -L option in your ldflags

    点赞 评论 复制链接分享