crawshaw / sqlite

Go SQLite3 driver
ISC License
561 stars 67 forks source link

Unable to build on Windows #137

Open CaptainKraft opened 1 year ago

CaptainKraft commented 1 year ago

When trying to build via the Windows command prompt, I get these errors:

# crawshaw.io/sqlite
In file included from _cgo_export.c:4:
cgo-gcc-export-header-prolog:49:34: error: redeclaration of 'go_sqlite_auth_tramp' cannot add 'dllexport' attribute
auth.go:5:13: note: previous declaration is here
cgo-gcc-export-header-prolog:50:35: warning: redeclaration of 'func_tramp' should not add 'dllexport' attribute [-Wdll-attribute-on-redeclaration]
func.go:22:14: note: previous declaration is here
cgo-gcc-export-header-prolog:51:35: warning: redeclaration of 'step_tramp' should not add 'dllexport' attribute [-Wdll-attribute-on-redeclaration]
func.go:23:14: note: previous declaration is here
cgo-gcc-export-header-prolog:52:35: warning: redeclaration of 'final_tramp' should not add 'dllexport' attribute [-Wdll-attribute-on-redeclaration]
func.go:24:14: note: previous declaration is here
cgo-gcc-export-header-prolog:54:34: warning: redeclaration of 'go_strm_w_tramp' should not add 'dllexport' attribute [-Wdll-attribute-on-redeclaration]
session.go:22:13: note: previous declaration is here
cgo-gcc-export-header-prolog:55:34: warning: redeclaration of 'go_strm_r_tramp' should not add 'dllexport' attribute [-Wdll-attribute-on-redeclaration]
session.go:23:13: note: previous declaration is here
cgo-gcc-export-header-prolog:58:35: error: redeclaration of 'log_fn' cannot add 'dllexport' attribute
sqlite.go:55:14: note: previous declaration is here

After installing cygwin and the appropriate libraries, I get this error when trying to build:

C:\Program Files\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lwinpthread: No such file or directory
collect2: error: ld returned 1 exit status

This is at the bottom of the README: By default it requires some pthreads DLL on Windows. To avoid it, supply CGOLDFLAGS="-static" when building your application.

But, setting CGOLDFLAGS to "-static" does nothing. However, in cygwin, if I export CGO_LDFLAGS to "-static", then I get a new error:

# runtime/cgo
gcc_libinit_windows.c: In function ‘_cgo_beginthread’:
gcc_libinit_windows.c:136:27: error: implicit declaration of function ‘_beginthread’; did you mean ‘_cgo_beginthread’? [-Werror=implicit-function-declaration]
  136 |                 thandle = _beginthread(func, 0, arg);
      |                           ^~~~~~~~~~~~
      |                           _cgo_beginthread
cc1: all warnings being treated as errors