how to build "go-sqlite3" under windows with x64

2,921 views
Skip to first unread message

平民四月份

unread,
Aug 29, 2012, 10:46:23 PM8/29/12
to golang-nuts, golang...@googlegroups.com
Hi all:
     who can tell me how to build "https://github.com/mattn/go-sqlite3" under windows with x64. i follow these steps. but i can't pass the test:
     
" you are using Windows, you can get pkg-config from below.
Go does not support static linking for external C library; sqlite3 should be built as a shared library. If it runs on Windows, it needs dll.
          Finally, this package can be installed with the go get command:"
         "
         
     just like   Guillermo Estrada 's comment in this thread https://groups.google.com/forum/?fromgroups=#!topic/golang-nuts/-Oxx54zCK9E:
         "Just a comment on that, pkg-config depends on GTK runtime libraries too, specifically libglib-2.0-0 and God knows what else. Problem with this kind of configurations is that just downloading the pkg-config executable under   
           windows is not enough, it won't run.....

   
 

--
 Face the sea, for the spring flowers blossoming




平民四月份

unread,
Aug 30, 2012, 2:34:40 AM8/30/12
to golang-nuts, golang...@googlegroups.com
Hi all. i got the solution. i hope it can help someone like me .

1. install tdm64-gcc
2. download the source code of sqlite3
4. unzip it and copy all files except shell.c to  github.com/mattn/go-sqlite3 directory
5. change sqlite3.go
    1) delete "#cgo pkg-config: sqlite3"
    2) change #include <sqlite3.h> to  #include "sqlite3.h"
    3) add
           #cgo windows LDFLAGS: -lmingwex -lmingw32
       #cgo windows CFLAGS: -fno-stack-check -fno-stack-protector -mno-stack-arg-probe


6. go install github.com/mattn/go-sqlite3  and test it 


the final sqlite3.go's beginning like this:

package sqlite

/*
#include "sqlite3.h"
#include <stdlib.h>
#include <string.h>
#cgo windows LDFLAGS: -lmingwex -lmingw32
#cgo windows CFLAGS: -fno-stack-check -fno-stack-protector -mno-stack-arg-probe
static int
_sqlite3_bind_text(sqlite3_stmt *stmt, int n, char *p, int np) {
  return sqlite3_bind_text(stmt, n, p, np, SQLITE_TRANSIENT);
}

static int
_sqlite3_bind_blob(sqlite3_stmt *stmt, int n, void *p, int np) {
  return sqlite3_bind_blob(stmt, n, p, np, SQLITE_TRANSIENT);
}


*/
import "C"
....
//====================================================

Dawid Polak

unread,
Oct 20, 2012, 6:17:28 AM10/20/12
to golan...@googlegroups.com, golang...@googlegroups.com
I prepared go-sqlite3 version, special for Windows x64 (with levgun's changes)

-DeyV

mattn

unread,
Oct 26, 2012, 2:05:01 AM10/26/12
to golan...@googlegroups.com, golang...@googlegroups.com
Could you please send me a pull-request?

Carlos Castillo

unread,
Oct 27, 2012, 11:28:12 PM10/27/12
to golan...@googlegroups.com, golang...@googlegroups.com
Unfortunately the change fails to build on OSX.

I have been able to make a patch that only does the above patch on windows, with only a one line change to sqlite3.go, which (hopefully) doesn't change the build on any other platforms.

Dawid Polak

unread,
Oct 30, 2012, 4:25:51 AM10/30/12
to golan...@googlegroups.com, golang...@googlegroups.com

Yes, of course, but, unfortunately, I don't know, how make it compatible with linux/mac version. 
DeyV
Reply all
Reply to author
Forward
0 new messages