Skip to content

Ristretto Jemalloc linking error when running ./tesh.sh #2226

Open

Description

@kianmeng

Describe the bug

Building projects that depend on dgraph-io/ristretto/v2 (such as dgraph-io/badger/v4 in this case) fails on a standard Ubuntu installation due to a CGO linking error with the jemalloc library, even when libjemalloc-dev is installed.

To Reproduce

Steps to reproduce the behavior:

  1. sudo apt install libjemalloc-dev
  2. git clone https://github.com/hypermodeinc/badger.git
  3. cd badger
  4. ./tesh.sh
  5. See error

Expected behavior

The Ristretto library should compile successfully with the standard go build command when libjemalloc-dev is installed. The CGO configuration should automatically include the required linker flags to resolve the C function symbols.

Screenshots

$ ./test.sh 
go version go1.25.0 linux/amd64
./test.sh: line 8: [: =: unary operator expected
/tmp/badger/badger /tmp/badger
github.com/dgraph-io/ristretto/v2/z
# github.com/dgraph-io/ristretto/v2/z
/home/foobar/go/pkg/mod/github.com/dgraph-io/ristretto/[email protected]/z/calloc_jemalloc.go:74:9: could not determine what C.je_calloc refers to
/home/foobar/go/pkg/mod/github.com/dgraph-io/ristretto/[email protected]/z/calloc_jemalloc.go:104:3: could not determine what C.je_free refers to
/home/foobar/go/pkg/mod/github.com/dgraph-io/ristretto/[email protected]/z/calloc_jemalloc.go:144:2: could not determine what C.je_mallctl refers to
/home/foobar/go/pkg/mod/github.com/dgraph-io/ristretto/[email protected]/z/calloc_jemalloc.go:171:2: could not determine what C.je_malloc_stats_print refers to

Environment

  • OS: Ubuntu 25.04
  • Language: go version go1.25.0 linux/amd64

Additional context

None.

Activity

  1. linear commented on Sep 28, 2025

    @linear
  2. changed the title [-]Ristretto Jemalloc Linking when running ./tesh.sh[/-] [+]Ristretto Jemalloc linking error when running ./tesh.sh[/+] on Sep 28, 2025
  3. Amr-Shams commented on Oct 25, 2025

    @Amr-Shams

    I have faced the same issue, but for now to skip this part I have changed the script tags from jemalloc to badger_nojemalloc, I believe this issue is a linking error not app error

  4. Amr-Shams commented on Oct 25, 2025

    @Amr-Shams

    I have faced the same issue, but for now to skip this part I have changed the script tags from jemalloc to badger_nojemalloc, I believe this issue is a linking error not app error

    Well, it works now i have installed the jemalloc from the repo

    sudo dnf remove jemalloc jemalloc-devel
    sudo dnf install autoconf automake libtool make gcc git
    
    git clone https://github.com/jemalloc/jemalloc.git
    cd jemalloc
    ./autogen.sh --with-jemalloc-prefix=je_
    make
    sudo make install
    

    and now i can cd to badger to try it out but you have to export some vars

    export CGO_CFLAGS="-I/usr/local/include"
    export CGO_LDFLAGS="-L/usr/local/lib -ljemalloc"
    export LD_LIBRARY_PATH="/usr/local/lib"
    go clean -modcache
    go build -tags jemalloc ./...
    
    
  5. github-actions commented on Jun 21, 2026

    @github-actions

    This issue has been stale for 60 days and will be closed automatically in 7 days. Comment to keep it open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions