Giter VIP home page Giter VIP logo

Comments (2)

alx696 avatar alx696 commented on May 21, 2024 1

@linxGnu Thanks very much for your response. After add CGO_CFLAGS and CGO_LDFLAGS, it works.

Dockerfile:

FROM registry.cn-shanghai.aliyuncs.com/xm69/alpine-rocksdb-apk AS app
WORKDIR /home
COPY code .
ENV GOPROXY=https://goproxy.cn
RUN set -eux && \
  #设置源
  echo "http://mirrors.ustc.edu.cn/alpine/edge/main/" > /etc/apk/repositories && \
  echo "http://mirrors.ustc.edu.cn/alpine/edge/community/" >> /etc/apk/repositories && \
  echo "http://mirrors.ustc.edu.cn/alpine/edge/testing/" >> /etc/apk/repositories && \
  apk update && \
  #安装RocksDB
  apk add --allow-untrusted /rocksdb.apk /rocksdb-dev.apk && \
  #打印编译环境
  echo "编译环境:$(uname -a)" && \
  #安装Golang环境
  apk add build-base go && \
  #下载并校验Golang模块
  go mod download && go mod verify && \
  #编译Golang应用
  # https://github.com/linxGnu/grocksdb/issues/24#issuecomment-752988851
  CGO_CFLAGS="-I/usr/include/rocksdb" \
  CGO_LDFLAGS="-L/usr/lib -lrocksdb -lstdc++ -lm -lz -lsnappy -llz4 -lzstd" \
  go build -o /home/main

If your CPU support SSE4.2, you can use rocksdb packages in alpine.

Shared library is smaller than static lib, especially in alpine. And rocksdb packages in alpine is also compiles shared library.

No need to go get -u github.com/linxGnu/grocksdb when Using Go Modules. Just install RocksDB first.

Ubuntu Install RocksDB:

$ sudo apt install -y libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev
$ PORTABLE=1 make -j32 shared_lib
$ sudo make install-shared
$ sudo su
# echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig

from grocksdb.

linxGnu avatar linxGnu commented on May 21, 2024

@alx696 thank you very much for trying grocksdb.

Yeah, builtin static lib at the moment is limited to libc, not musl compatible with alpine.

So, I think you could:

  • Build rocksdb as static lib inside your alpine image
  • Build grocksdb and your application: go build -tags static

Or, if you want shared lib:

  • Build rocksdb as shared lib inside your alpine image
  • Build grocksdb and your applicaion:
CGO_CFLAGS="-I/path/to/rocksdb/include" \
CGO_LDFLAGS="-L/path/to/rocksdb -lrocksdb -lstdc++ -lm -lz -lsnappy -llz4 -lzstd" \
go build

Please tell me if that works for you.

from grocksdb.

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.