microo8 / plgo

easily create postgresql extensions in golang; moved to gitlab.com/microo8/plgo
292 stars 23 forks source link

Build error on Linux #32

Closed PaulHatch closed 4 years ago

PaulHatch commented 4 years ago

It seems that adding Windows support updated the CFLAGS line to #cgo CFLAGS: -I"/usr/include/postgresql/server" -fpic has added quotes which were not present previously, causing what was the end of the line to be the middle. The path here is provided from the call to pg_config --includedir-server which includes a newline character at the end, since this newline is no longer the final character in the declaration this produces a syntax error. This is fixed by getcorrectpath for Windows only, leaving the Linux version failing.

Here is a Dockerfile for reproducing this issue:

FROM golang:1.13

RUN apt-get update && \
    apt-get -y install postgresql-server-dev-11 && \
    go get -u github.com/microo8/plgo/plgo && \
    plgo /go/src/github.com/microo8/plgo/example/.

Running this produces the following error:

can't load package: package main: /go/plgo072699724/pl.go: invalid #cgo line: #cgo CFLAGS: -I"/usr/include/postgresql/11/server

By trimming the newline character from the end of the path for the non-Windows version of getcorrectpath I am able to build successfully. (https://github.com/microo8/plgo/pull/33) Not sure if I am missing something here since based on my understanding I'd expect any Linux build to hit the same problem and I haven't been able to find any other reference to this error.

microo8 commented 4 years ago

Merged the #33 PR