10

So I have a very simple web app that just serves an html file right now, and my code works on my laptop, but not on heroku's servers. There are no errors while compiling, but when I try to visit the site. the app crashes. version `GLIBC_2.32' not found I checked the logs and it says that it needs 'GLIBC_2.32' which is not found. I'm very new to Heroku and making web apps, I don't know how to install that dependency

MikunoNaka
  • 103
  • 1
  • 1
  • 5

3 Answers3

30

Try building without cgo:

CGO_ENABLED=0 go build

CGO_ENABLED=0 disables calling C code (import "C"). This means that some features from the standard library or 3rd-party libraries might be unavailable or a pure Go implementation is used instead. What that means for your application in terms of functionality and performance really depends on what your application does. I suggest you run your tests before deploying to production ;-) In most cases it'll work just fine.


More info about CGO_ENABLED:

fnkr
  • 9,428
  • 6
  • 54
  • 61
1

I faced to the same problem while using multi-step docker. First build app in a builder docker than copy the binary to new container. Because the original golang 1.19 has changed my prebuilt binaries were crashing in the second container with the error GLIBC_2.32 not found

I my case setting CGO_ENABLED is not an option.

1st workaround is to compile the app in the running container

2nd workaround to find the previous version of the base golang 1.19 docker image.

Both worked for me.

serkan
  • 555
  • 7
  • 13
0

Due to some dependencies, setting CGO_ENABLED=0 was not an option. The best alternative seems to be building Go in a docker container. Here's a Dockerfile created with the help of ChatGPT to build an image based on Ubuntu 18.04, which will only require GLIBC_2.27

FROM ubuntu:18.04

# Install necessary packages
RUN apt-get update -y && apt-get install -y --no-install-recommends \
    curl \
    ca-certificates \
        build-essential

RUN apt-get update -y
RUN apt-get install -y libx11-dev

# Download and install Go
ENV GO_VERSION 1.20.6
RUN curl -LO "https://go.dev/dl/go1.20.6.linux-amd64.tar.gz" && \
    tar -C /usr/local -xzf "go1.20.6.linux-amd64.tar.gz" && \
    rm "go1.20.6.linux-amd64.tar.gz"

# Set Go environment variables
ENV PATH="/usr/local/go/bin:${PATH}"
ENV GOPATH="/go"
ENV GOBIN="/go/bin"

# Create a directory for Go workspace
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"

# Set CGO_ENABLED to enable cgo
RUN go env -w CGO_ENABLED=1

# Set the working directory
WORKDIR $GOPATH/src

COPY . .

RUN ls

RUN go build .

# Print Go version to verify the installation
RUN go version

# Your additional configurations and code can be added here.

# By default, run bash for interactive access (optional)
CMD ["/bin/bash"]
mowwwalker
  • 16,634
  • 25
  • 104
  • 157