karalabe / xgo

Go CGO cross compiler
MIT License
2.14k stars 280 forks source link

provide additional header files #209

Open nrobert13 opened 3 years ago

nrobert13 commented 3 years ago

I'm trying to compile a program which requires systemd's headers. like this:

GOPATH=/home/src xgo -x -v -image xgo-latest-sd ./

The Dockerfile of xgo-latest-sd looks like this, to add the required headers.

FROM karalabe/xgo-latest

RUN apt-get update && \
    apt-get install -y libsystemd-dev

the header is installed under:

# docker run --rm -it --entrypoint /usr/bin/find xgo-latest-sd -- /usr/ -name sd-journal.h
/usr/include/systemd/sd-journal.h

but as far as I can tell cgo doesn't find it due to -I $WORK/b206/

CGO_LDFLAGS='"-fPIE"' /usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b206/ -importpath github.com/coreos/go-systemd/sdjournal -- -I $WORK/b206/ -fPIE ./journal.go
# github.com/coreos/go-systemd/sdjournal
/go/pkg/mod/github.com/coreos/go-systemd@v0.0.0-20191104093116-d3cd4ed1dbcf/sdjournal/journal.go:27:33: fatal error: systemd/sd-journal.h: No such file or directory
 // #include <systemd/sd-journal.h>
                                 ^
compilation terminated.

is there a way to get this compiled with xgo?

thanks in advance.

nrobert13 commented 3 years ago

got it working for specific target like

GOPATH=/home/src xgo  -image xgo-latest-sd  -targets linux/arm-7 ./