Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark Souls level frustration with compilation project with this library #83

Open
M1chlCZ opened this issue Apr 21, 2023 · 1 comment
Open

Comments

@M1chlCZ
Copy link

M1chlCZ commented Apr 21, 2023

Alright, I am having deep trouble to get this stuff up and running inside me project.

So first I've tried to compile on Mac, natively, with musl, with zig cc. Various errors, but most often that, tried to add -I/ -L flags to point out to downloaded package from google, nothing always more or less this error:

/root/go/pkg/mod/github.com/galeone/tensorflow/tensorflow/go@v0.0.0-20221023090153-6b7fa0680c3e/attrs.go:20:11: fatal error: tensorflow/c/c_api.h: No such file or directory
    20 | // #include "tensorflow/c/c_api.h"
       |           ^~~~~~~~~~~~~~~~~~~~~~
 compilation terminated.

So alright, there is the added difficulty with ARM64 and x64_86 libs, so...why not try a docker, with the image listed on this github:

FROM tensorflow/tensorflow:2.9.1

RUN apt-get update && apt-get install -y \
    wget \
    git \
    gcc \
    build-essential

ENV GOLANG_VERSION 1.20.3
RUN wget https://golang.org/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz && \
    tar -C /usr/local -xzf go${GOLANG_VERSION}.linux-amd64.tar.gz && \
    rm go${GOLANG_VERSION}.linux-amd64.tar.gz

ENV PATH /usr/local/go/bin:$PATH

WORKDIR /app

COPY . .

RUN  go get -d -v ./... && \
    CGO_ENABLED=1 go build -o main .

LABEL authors="M1chl"

ENTRYPOINT ["./main", "arg1"]

Well no dice, same error. I by no means want to waste any ones time, but I would really need to get this up and running.

Does anyone has any suggestion how to fix it?

@M1chlCZ
Copy link
Author

M1chlCZ commented Apr 21, 2023

Alright I managed to fixed with help of our ML/AI overlords

# Use the official Golang image as the base image
FROM golang:1.20.3 as builder

# Install required dependencies
RUN apt-get update && apt-get install -y \
     wget \
     git \
     gcc \
     build-essential

# Download and install TensorFlow C library
RUN wget https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.9.1.tar.gz && \
    tar -C /usr -xzf libtensorflow-cpu-linux-x86_64-2.9.1.tar.gz && \
    ldconfig && \
    rm libtensorflow-cpu-linux-x86_64-2.9.1.tar.gz

# Set the environment variables to help the Go compiler find the TensorFlow C library
ENV LD_LIBRARY_PATH /usr/local/lib
ENV CGO_CFLAGS "-I/usr/local/include"
ENV CGO_LDFLAGS "-L/usr/local/lib"

# Create a working directory for your Go project
WORKDIR /app

# Copy the Go project files into the container
COPY . .

# Build the Go project
RUN go mod tidy && \
    go build -o main .

#Use the official TensorFlow image as the base image
FROM ubuntu:22.04

COPY --from=builder /app/main .
COPY --from=builder /usr/lib/libtensorflow.so.2 /usr/local/lib/
COPY --from=builder /usr/lib/libtensorflow_framework.so.2 /usr/local/lib/

# Set the environment variables to help the runtime find the TensorFlow C library
ENV LD_LIBRARY_PATH /usr/local/lib

LABEL authors="M1chl"

ENTRYPOINT ["./main"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant