Skip to content

pg_query_go does not work on MinGW (GCC on Windows) #138

@kanryu

Description

@kanryu

Summary

When I run a program using pg_query_go on Windows with go run, pg_query_go gets a build error.

What I tried

  • a empty dir
  • Save the sample code from README.md as main.go
  • go mod init example.com/m
  • go mod tidy
    • require github.com/pganalyze/pg_query_go/v6 v6.1.0
  • go run main.go

Solution

Remove the -fstack-protector option from parser/perser.go. It is not supported on Windows.

Build errors encountered during the attempt

$ go run main.go
# command-line-arguments
C:\local\gnu\Go-1.22.0\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/local/gnu/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kanryu\AppData\Local\Temp\go-link-995018982\000005.o: in function `_fingerprintRTEPermissionInfo':
C:/Users/kanryu/go/pkg/mod/github.com/pganalyze/pg_query_go/v6@v6.1.0/parser/include/pg_query_fingerprint_defs.c:6525: undefined reference to `__stack_chk_fail'
C:/local/gnu/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kanryu\AppData\Local\Temp\go-link-995018982\000005.o: in function `_fingerprintVar':
C:/Users/kanryu/go/pkg/mod/github.com/pganalyze/pg_query_go/v6@v6.1.0/parser/include/pg_query_fingerprint_defs.c:730: undefined reference to `__stack_chk_fail'
C:/local/gnu/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kanryu\AppData\Local\Temp\go-link-995018982\000005.o: in function `_fingerprintJsonReturning':
C:/Users/kanryu/go/pkg/mod/github.com/pganalyze/pg_query_go/v6@v6.1.0/parser/include/pg_query_fingerprint_defs.c:2695: undefined reference to `__stack_chk_fail'
C:/local/gnu/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kanryu\AppData\Local\Temp\go-link-995018982\000005.o: in function `_fingerprintNode':
C:\Users\kanryu\go\pkg\mod\github.com\pganalyze\pg_query_go\v6@v6.1.0\parser/pg_query_fingerprint.c:310: undefined reference to `__stack_chk_fail'
C:/local/gnu/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kanryu\AppData\Local\Temp\go-link-995018982\000005.o: in function `_fingerprintAlterCollationStmt':
C:/Users/kanryu/go/pkg/mod/github.com/pganalyze/pg_query_go/v6@v6.1.0/parser/include/pg_query_fingerprint_defs.c:9525: undefined reference to `__stack_chk_fail'
C:/local/gnu/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kanryu\AppData\Local\Temp\go-link-995018982\000005.o:C:/Users/kanryu/go/pkg/mod/github.com/pganalyze/pg_query_go/v6@v6.1.0/parser/include/pg_query_fingerprint_conds.c:579: more undefined references to `__stack_chk_fail' follow
C:/local/gnu/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kanryu\AppData\Local\Temp\go-link-995018982\000005.o:pg_query_fingerprint.c:(.rdata$.refptr.__stack_chk_guard[.refptr.__stack_chk_guard]+0x0): undefined reference to `__stack_chk_guard'
C:/local/gnu/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kanryu\AppData\Local\Temp\go-link-995018982\000010.o: in function `pg_query_raw_parse':
C:\Users\kanryu\go\pkg\mod\github.com\pganalyze\pg_query_go\v6@v6.1.0\parser/pg_query_parse.c:116: undefined reference to `__stack_chk_fail'
C:/local/gnu/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kanryu\AppData\Local\Temp\go-link-995018982\000011.o: in function `pg_query_raw_parse_plpgsql':
C:\Users\kanryu\go\pkg\mod\github.com\pganalyze\pg_query_go\v6@v6.1.0\parser/pg_query_parse_plpgsql.c:396: undefined reference to `__stack_chk_fail'
C:/local/gnu/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kanryu\AppData\Local\Temp\go-link-995018982\000013.o: in function `pg_query_scan':
C:\Users\kanryu\go\pkg\mod\github.com\pganalyze\pg_query_go\v6@v6.1.0\parser/pg_query_scan.c:164: undefined reference to `__stack_chk_fail'
C:/local/gnu/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kanryu\AppData\Local\Temp\go-link-995018982\000014.o: in function `pg_query_split_with_scanner':
C:\Users\kanryu\go\pkg\mod\github.com\pganalyze\pg_query_go\v6@v6.1.0\parser/pg_query_split.c:163: undefined reference to `__stack_chk_fail'
C:/local/gnu/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kanryu\AppData\Local\Temp\go-link-995018982\000016.o: in function `protobuf_c_message_pack_to_buffer':
C:\Users\kanryu\go\pkg\mod\github.com\pganalyze\pg_query_go\v6@v6.1.0\parser/protobuf-c.c:2011: undefined reference to `__stack_chk_fail'
C:/local/gnu/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kanryu\AppData\Local\Temp\go-link-995018982\000016.o:C:\Users\kanryu\go\pkg\mod\github.com\pganalyze\pg_query_go\v6@v6.1.0\parser/protobuf-c.c:1644: more undefined references to `__stack_chk_fail' follow
collect2.exe: error: ld returned 1 exit status

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions