Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import and use CGO Brotli implementation from google?

Tags:

go

cgo

brotli

I am trying to import and use cbrotli implementation from google as below:

import (
    "fmt"
    "io/ioutil"

    cbrotli "github.com/google/brotli/go/cbrotli"
)

But I am getting the below error while trying to run the program:

learn-go [master●●] % CGO_CFLAGS="-I /dev/projects/go/learn-go/src/brotli/c/include/brotli" go run cmd/compress/main.go
# github.com/google/brotli/go/cbrotli
src/github.com/google/brotli/go/cbrotli/reader.go:13:10: fatal error: 'brotli/decode.h' file not found
#include <brotli/decode.h>

I am not sure how to pass some C flags to make sure that I can use the brotli implementation

like image 983
Aditya Singh Avatar asked Nov 11 '17 00:11

Aditya Singh


1 Answers

Assuming you already have built brotli, if not, there is an installation instructions in their Github page:

$ mkdir out && cd out
$ ../configure-cmake
$ make
$ make test
$ make install

When building your Go app, you only need to pass -I ~<prefix>/include, where <prefix> is where you installed the header files for brotli. If you did not configure this prefix, it is usually in /usr/local.

After this, you can run using:

$ CGO_FLAGS='-I <prefix>/include' CGO_FLAGS='-L <prefix>/lib' LD_LIBRARY_PATH='<prefix>/lib' go run cmd/compress/main.go

Note: You don't need to add "brotli" at the end of your CGO_FLAGS

like image 160
ssemilla Avatar answered Nov 15 '22 16:11

ssemilla