otiai10/gosseract

Can't build app in docker(/usr/local/go/pkg/tool/linux_amd64/link: running g++ failed: exit status 1)

VerusK opened this issue · 3 comments

Summary

Getting this log in gitlab CI:

/usr/local/go/pkg/tool/linux_amd64/link: running g++ failed: exit status 1
/usr/bin/ld: /tmp/go-link-1791098924/000007.o: in function `_cgo_2ac87069779a_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:58: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/libtesseract.a(par_control.o): in function `tesseract::Tesseract::PrerecAllWordsPar(GenericVector<tesseract::WordData> const&) [clone ._omp_fn.0]':
(.text+0xf): undefined reference to `omp_get_num_threads'
/usr/bin/ld: (.text+0x16): undefined reference to `omp_get_thread_num'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/libtesseract.a(par_control.o): in function `tesseract::Tesseract::PrerecAllWordsPar(GenericVector<tesseract::WordData> const&)':
(.text+0x52f): undefined reference to `GOMP_parallel'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/libtesseract.a(parallel.o): in function `tesseract::Parallel::Forward(bool, tesseract::NetworkIO const&, tesseract::TransposedArray const*, tesseract::NetworkScratch*, tesseract::NetworkIO*) [clone ._omp_fn.0]':
(.text+0xc2): undefined reference to `omp_get_num_threads'
/usr/bin/ld: (.text+0xc9): undefined reference to `omp_get_thread_num'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/libtesseract.a(parallel.o): in function `tesseract::Parallel::Backward(bool, tesseract::NetworkIO const&, tesseract::NetworkScratch*, tesseract::NetworkIO*) [clone ._omp_fn.1]':
(.text+0x182): undefined reference to `omp_get_num_threads'
/usr/bin/ld: (.text+0x189): undefined reference to `omp_get_thread_num'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/libtesseract.a(parallel.o): in function `tesseract::Parallel::Forward(bool, tesseract::NetworkIO const&, tesseract::TransposedArray const*, tesseract::NetworkScratch*, tesseract::NetworkIO*)':
...

and many more such lines

Reproducibility

Reproducibility Frequency

  • 100%

Reproducible Dockerfile

FROM amd64/golang:1.19.5-buster

# installing chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
RUN apt-get update && apt-get -y install google-chrome-stable

# installing tesseract-ocr
RUN apt-get update && apt-get install -y \
    upx-ucl \
    apt-transport-https \
    lsb-release \
    libtesseract-dev \
    libleptonica-dev \
    && rm -rf /var/lib/apt/lists/*

RUN echo "deb https://notesalexp.org/tesseract-ocr5/$(lsb_release -cs)/ $(lsb_release -cs) main" \
    | tee /etc/apt/sources.list.d/notesalexp.list > /dev/null

RUN wget -q -O - https://notesalexp.org/debian/alexp_key.asc | apt-key add -

RUN apt-get update && apt-get install -y \
    tesseract-ocr

COPY ./bin /usr/local/bin

Environment

uname -a
Linux runner-xxurkrix-project-42364102-concurrent-0 5.4.109+ #1 SMP Wed Jun 16 20:00:10 PDT 2021 x86_64 GNU/Linux
go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.5"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/builds/manuals3/backend/go/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build[35](https://gitlab.com/manuals3/backend/go/-/jobs/3604144596#L35)22[59](https://gitlab.com/manuals3/backend/go/-/jobs/3604144596#L59)2991=/tmp/go-build -gno-record-gcc-switches"
go version
go version go1.19.5 linux/amd64
tesseract --version
tesseract 5.3.0
 leptonica-1.76.0
  libgif 5.1.4 : libjpeg 6b (libjpeg-turbo 1.5.2) : libpng 1.6.36 : libtiff 4.1.0 : zlib 1.2.11 : libwebp 0.6.1 : libopenjp2 2.3.0
 Found AVX2
 Found AVX
 Found FMA
 Found SSE4.1
 Found OpenMP 201511
 Found libarchive 3.3.3 zlib/1.2.11 liblzma/5.2.4 bz2lib/1.0.6 liblz4/1.8.3 libzstd/1.3.8
 Found libcurl/7.64.0 OpenSSL/1.1.1n zlib/1.2.11 libidn2/2.0.5 libpsl/0.20.2 (+libidn2/2.0.5) libssh2/1.8.0 nghttp2/1.36.0 librtmp/2.3

How did you build your bin?

go build -a -installsuffix cgo -tags=jsoniter -o "${BIN_FILE_PATH}"

I solved the problem. Actually I was using ldflags:

-ldflags="-s -w -extldflags '-static'"

after removing -extldflags '-static' everything works fine :)