dongrou839975 2019-09-21 09:12
浏览 230

我应该安装什么软件包而不是libpcre ++-dev来在Alpine Golang中使用C代码?

I have a Golang program inside a docker container (I use Ubuntu 18). Also I use github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre for regex in my Golang app. Before using this library I should install libpcre++-dev this way:

sudo apt-get install libpcre++-dev

But I use golang:alpine in my Dockerfile and this is no libpcre++-dev library in alpine packages.

What package should I install instead of libpcre++-dev?

p.s. I have tried to install libc6-compat, pcre pcre-dev, libpcrecpp but I see this error:

github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre /go/pkg/mod/github.com/glenn-brown/golang-pkg-pcre@v0.0.0-20120522223659-48bb82a8b8ce/src/pkg/pcre/pcre.go:52:10: fatal error: pcre.h: No such file or directory #include ^~~~~~~~ compilation terminated

My Dockerfile:

FROM golang:alpine

RUN apk update
RUN apk upgrade
RUN apk add --update --no-cache build-base gcc g++ pcre pcre-dev libc6-compat

# Install git + SSL ca certificates.
# Git is required for fetching the dependencies.
# Ca-certificates is required to call HTTPS endpoints.
RUN apk update && apk add --no-cache curl git ca-certificates tzdata \
 && update-ca-certificates 2> /dev/null || true

I build my app this way:

- CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-w -s" -o bin/backend ./cmd/backend/main.go

EDIT

I have change my Dockerfile (add line below)

RUN apk add --update --no-cache build-base gcc g++ pcre pcre-dev libc6-compat

And now I have a new error:

Error loading shared library libpcre.so.1: No such file or directory (needed by /bin/backend)

  • 写回答

2条回答 默认 最新

  • doucaigai7176 2019-09-21 10:27
    关注

    You can try one of these, as both package

    RUN apk add --virtual build-dependencies 
    RUn apk add --no-cache build-base gcc
    

    build-essential is a metapackage (a package that installs many other packages, like g++ and gcc: the GNU C & C++ compilers).

    Or you can install the alpine sdk.

    You can start with alpine-sdk, which is a "metapackage that pulls in the most essential packages used to build new packages." http://wiki.alpinelinux.org/wiki/Developer_Documentation has more info.

    RUN apk add --update alpine-sdk
    

    docker-alpine-issues-24

    Or you can use golang:latest which will work fine.

    FROM golang:latest
    RUN apt-get update 
    RUN apt-get install libpcre++-dev -y
    
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题