Coder Social home page Coder Social logo

static linking to dlib about go-face HOT 6 CLOSED

kagami avatar kagami commented on July 27, 2024
static linking to dlib

from go-face.

Comments (6)

Kagami avatar Kagami commented on July 27, 2024

Should be possible in case of dlib, not sure about mkl. Might try with e.g. openblas instead.

from go-face.

Kagami avatar Kagami commented on July 27, 2024

Closing because it's out of scope of go-face.
Should be possible with something like CGO_LDFLAGS="-static" but don't have time to test this, because you also need static (.a) version of all libraries that dlib depends on.

from go-face.

tpoxa avatar tpoxa commented on July 27, 2024

@frpunzalan I managed to build go-face application statically in docker.
Its based on Ubuntu 19.04 base image.

Dockerfile.ubuntu19.04

FROM ubuntu:19.04 as base
RUn apt-get update
RUN apt-get update && apt-get install pkg-config libdlib-dev libopenblas-dev libgfortran-8-dev libjpeg-turbo8-dev -y
ADD dlib-1.pc /usr/local/lib/pkgconfig/
RUN pkg-config --cflags  -- dlib-1

dlib-1.pc

libdir=/usr/lib/x86_64-linux-gnu
includedir=/usr/include

Name: dlib
Description: Numerical and networking C++ library
Version: 19.10.0
Libs: -L${libdir} -ldlib -lblas -llapack -lgfortran -lquadmath
Cflags: -I${includedir}
Requires:

These two files give you basic environment with dev dependencies ready for static build. I named this image dlibubuntu

Next goes golang 1.13.8 base image with go-face library built in the $GOPATH
Because go-face installation takes much time I decided to make it as separate docker image.

FROM dlibubuntu as builder
RUN apt-get install wget git gcc -y

RUN wget https://dl.google.com/go/go1.13.8.linux-amd64.tar.gz
RUN tar -xf go1.13.8.linux-amd64.tar.gz
RUN mv go /usr/local

ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH
RUN mkdir $GOPATH
RUN go get -v github.com/Kagami/go-face 

Last one. Your golang application which is using go-face. Basically app the same as example one. I provide here only its Dockerfile.

FROM goface:latest as builder
WORKDIR /go/src/service
ADD . .
RUN CGO_LDFLAGS="-static" CGO_ENABLED=1 GOOS=linux go build

FROM alpine
WORKDIR /root
COPY --from=builder /go/src/service /root

Run

docker run -it facerecognize:latest /root/service
Nayoung

One restriction here user app should be in GOPATH to re-use go-face package.
I hope this will help someone.

from go-face.

Jumanjii avatar Jumanjii commented on July 27, 2024

Hello @tpoxa ,
Thanks for your research with Docker.
Reproducing what you've done and fixing little issues I reached to have the example program running in the container (using go run).

Still, I'm fighting with an issue when trying to build the binary
using CGO_LDFLAGS="-static" CGO_ENABLED=1 GOOS=linux go build

Does the following error is bringing some bells to you?

(.text+0x9cd): undefined reference to `_gfortran_concat_string'

from go-face.

AgentNemo avatar AgentNemo commented on July 27, 2024

(.text+0x781): more undefined references to _gfortran_concat_string' follow
collect2`

i have the same error

from go-face.

vearutop avatar vearutop commented on July 27, 2024

I've managed to build static binary with dlib with such a Dockerfile and reduced ldflags in face.go.

// #cgo LDFLAGS: -ldlib
import "C"

https://github.com/vearutop/faces/blob/v0.1.4/vendor/github.com/Kagami/go-face/face_static.go

FROM ubuntu:22.04 as builder

RUN apt-get update
RUN apt-get install -y build-essential cmake curl
RUN curl -sLO https://go.dev/dl/go1.21.6.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz && rm -rf go1.21.6.linux-amd64.tar.gz
RUN mkdir /dlib && cd /dlib && curl -sLO http://dlib.net/files/dlib-19.24.tar.bz2 && tar xf dlib-19.24.tar.bz2
RUN cd /dlib/dlib-19.24 && mkdir build && cd build && cmake .. && cmake --build . --config Release && make install && rm -rf /dlib

# Missing header file.
RUN cp /usr/local/include/dlib/external/libjpeg/*.h /usr/include/

# Building app.
WORKDIR /app
ADD . .
RUN CGO_LDFLAGS="-static" /usr/local/go/bin/go build -tags static .

# Exporting minimal docker image with pre-built binary.
FROM alpine
WORKDIR /root
CMD ["/bin/faces", "-listen", "0.0.0.0:80"]
COPY --from=builder /app/faces /bin/faces

More info in a blog post.

from go-face.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.