Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to build on windows #25

Closed
dharmjit opened this issue Jan 23, 2020 · 5 comments · Fixed by #107
Closed

Not able to build on windows #25

dharmjit opened this issue Jan 23, 2020 · 5 comments · Fixed by #107

Comments

@dharmjit
Copy link

Hi, I am tryoing to build this project on windows and getting below error

$ go get github.com/lfittl/pg_query_go                                                                                                 # github.com/lfittl/pg_query_go/parser                                                                                                 In file included from .\include/c.h:1129:0,                                                                                                             from .\include/postgres.h:47,                                                                                                          from contrib_pgcrypto_sha1.c:50:                                                                                      .\include/port.h:17:19: fatal error: netdb.h: No such file or directory                                                                compilation terminated.

I have tried the modules step as well but no success. I have searched for netdb.h and this file is not there in the include folder.
How I can resolve this. Thanks

@dharmjit
Copy link
Author

Hi, Any update on this.

@maxiride
Copy link

maxiride commented May 3, 2020

I guess I have the same error as @dharmjit but the inline formatting really doesn't help in reading it 😅 (please fix it)

Microsoft Windows [Version 10.0.18363.778]
(c) 2019 Microsoft Corporation. All rights reserved.

D:\Federico\Projects>go get github.com/lfittl/pg_query_go
# github.com/lfittl/pg_query_go/parser
In file included from C:\Users\maxir\go\pkg\mod\github.com\lfittl\[email protected]\parser\include/c.h:1129,
                 from C:\Users\maxir\go\pkg\mod\github.com\lfittl\[email protected]\parser\include/postgres.h:47,
                 from contrib_pgcrypto_sha1.c:50:
C:\Users\maxir\go\pkg\mod\github.com\lfittl\[email protected]\parser\include/port.h:17:10: fatal error: netdb.h: No such file or directory
   17 | #include <netdb.h>
      |          ^~~~~~~~~
compilation terminated.

I really don't know what this is and what I'm talking about, so I tried a bare bone "googling" and a quick browsing led to similar issues in other codebases like here and here but you can find tons of them across multiple programming languages. From my understanding it all boils down to different dependencies under Windows and Unix.

Here is some info on the library.

The general agreement I found on the subject is to use a conditional including, under windows host the library to be used should be #include <winsock2.h> but further analysis is needed to pinpoint the fix.

Anyway the bug clearly isn't related specifically to github.com/lfittl/pg_query_go but rather to its external dependencies needs.


A temporary workaround I am using is to build my application in a linux docker container, not the best workflow but works.

@PatrLind
Copy link

I was just trying this out in a test project, but right now it seems like the include file that is missing is expected to be in this project. Is this because this is work in progress?
The include file that is missing should be parser/include/port/win32_port.h and is included from here:
https://github.com/pganalyze/pg_query_go/blob/main/parser/include/port.h#L24C29-L24C29

Compiler error on Widows:

# github.com/pganalyze/pg_query_go/v4/parser
In file included from ..\..\go\pkg\mod\github.com\pganalyze\pg_query_go\[email protected]\parser\include/c.h:1387,
                 from ..\..\go\pkg\mod\github.com\pganalyze\pg_query_go\[email protected]\parser\include/postgres.h:46,
                 from pg_query_internal.h:4,
                 from pg_query.c:2:
..\..\go\pkg\mod\github.com\pganalyze\pg_query_go\[email protected]\parser\include/port.h:24:10: fatal error: port/win32_port.h: No such file or directory
   24 | #include "port/win32_port.h"
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.

@lfittl
Copy link
Member

lfittl commented Nov 22, 2023

I was just trying this out in a test project, but right now it seems like the include file that is missing is expected to be in this project. Is this because this is work in progress? The include file that is missing should be parser/include/port/win32_port.h and is included from here: https://github.com/pganalyze/pg_query_go/blob/main/parser/include/port.h#L24C29-L24C29

Compiler error on Widows:

# github.com/pganalyze/pg_query_go/v4/parser
In file included from ..\..\go\pkg\mod\github.com\pganalyze\pg_query_go\[email protected]\parser\include/c.h:1387,
                 from ..\..\go\pkg\mod\github.com\pganalyze\pg_query_go\[email protected]\parser\include/postgres.h:46,
                 from pg_query_internal.h:4,
                 from pg_query.c:2:
..\..\go\pkg\mod\github.com\pganalyze\pg_query_go\[email protected]\parser\include/port.h:24:10: fatal error: port/win32_port.h: No such file or directory
   24 | #include "port/win32_port.h"
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.

This is because Postgres itself supports Windows, but libpg_query (and pg_query_go by extent) does not today. Its definitely possible, but requires pulling in the right files (and a Windows machine to test with). The relevant file, in case that helps, is in https://github.com/postgres/postgres/blob/master/src/include/port/win32_port.h - but its likely making this work is more complicated than just fixing the import by adding the missing file.

See pganalyze/libpg_query#44 - contributions welcome, but over the years nobody from the community has made the effort to try to fix this, and unfortunately neither I nor the other maintainers of the library run Windows ourselves, thus making this a bit hard to get fixed.

@lfittl
Copy link
Member

lfittl commented Jan 10, 2024

Windows support has been added in #107 and released as v5.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants