I have, but the following line didn't make much sense to me:
"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."
After sending my message, I took rsc's implementation of the sqlite
interface, added the fix for the undefined ___chkstk_ms [1] (didn't
need to change LDFLAGS), and was able to compile the amalgamation
source directly into the Go binary. I didn't do much testing with it,
but creating a new database and a few tables seemed to work fine. On
FreeBSD, I ran into a bunch of "unhandled relocation" errors, but
didn't have enough time to diagnose the problem. I'm probably
misunderstanding something about the current support for compiling C
code directly into a Go binary and linking in a static library.
My point is that getting SQLite to work with Go seems to be a bit of a
black art at the moment. There are discussions about reimplementing
the vfs layer, though I don't really understand what that's for. There
is some wrong or outdated information on the mailing list; issues that
may have required fixes 2 years ago, but not with the current version
of Go. Given how popular SQLite is for any applications requiring more
than plain text file storage, I think it would help many people to
have one definitive guide that describes the recommended practices for
getting SQLite to work with the current version of Go on various
platforms. Static linking would be better if it's possible to do, but
that's just the thing - I can't figure out what is and isn't supported
at the moment.
- Max
[1]
https://groups.google.com/d/msg/golang-nuts/VNP6Mwz_B6o/hhgIbxzdCQwJOn Sun, Dec 9, 2012 at 11:38 PM, James Cooper wrote:Hi,
Have you tried this package yet?
https://github.com/mattn/go-sqlite3The included example shows basic usage:
https://github.com/mattn/go-sqlite3/blob/master/example/main.gocheers
-- James
On Sunday, December 9, 2012 6:53:57 AM UTC-8, Maxim Khitrov wrote:
Hello,
I've read all the discussions that I could find on this topic, but I'm
still confused about the status of compilation or static linking of
SQLite. In the end, I'd like to have an executable that can open and
work with SQLite databases. It doesn't really matter whether this is
accomplished through cgo or some other method. Is there a way of
either compiling the SQLite amalgamation source directly into a Go
executable, or building it separately and then linking in the static
library, which works on Linux, BSD, OS X, and Windows?
If this is possible, could someone write a short guide for all of
these systems describing the steps from having a Go 1.0.3 installation
and SQLite amalgamation source to building an executable that can
interact with a SQLite database?
- Max
--
--