Skip to content

Building go-sqlite on system with other installed sqlite3 version #321

Closed
@darinkes

Description

@darinkes

If you import this Package on an OpenBSD 5.9 system your compiled tool will always print a warning:

./tool:/usr/lib/libsqlite3.so.32.0: ./tool: WARNING: symbol(sqlite3_version) size mismatch, relink your program

Problem is the installed version of sqlite3 differs from the one sqlite3-binding.c is copied from.

$ sqlite3 --version
3.9.2 OpenBSD
#define SQLITE_VERSION        "3.12.2"

Enabling the Build Tags "--tags 'libsqlite3 openbsd'" should fix this, but still this Warning occurs, because sqlite3-binding.c is compiled, nevertheless you want to use the system library.

This Diff fixes the Issue for me.

diff --git a/vendor/github.com/mattn/go-sqlite3/callback.go b/vendor/github.com/mattn/go-sqlite3/callback.go
index e2bf3c6..190b695 100644
--- a/vendor/github.com/mattn/go-sqlite3/callback.go
+++ b/vendor/github.com/mattn/go-sqlite3/callback.go
@@ -11,7 +11,11 @@ package sqlite3
 // code for SQLite custom functions is in here.

 /*
+#ifndef USE_LIBSQLITE3
 #include <sqlite3-binding.h>
+#else
+#include <sqlite3.h>
+#endif
 #include <stdlib.h>

 void _sqlite3_result_text(sqlite3_context* ctx, const char* s);
diff --git a/vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c b/vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c
index 7b82c55..caeabba 100644
--- a/vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c
+++ b/vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c
@@ -17,6 +17,7 @@
 ** language. The code for the "sqlite3" command-line shell is also in a
 ** separate file. This file contains only code for the core SQLite library.
 */
+#ifndef USE_LIBSQLITE3
 #define SQLITE_CORE 1
 #define SQLITE_AMALGAMATION 1
 #ifndef SQLITE_PRIVATE
@@ -189317,3 +189318,5 @@ static int sqlite3Fts5VocabInit(Fts5Global *pGlobal, sqlite3 *db){
 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS5) */

 /************** End of fts5.c ************************************************/
+
+#endif // !USE_LIBSQLITE3
diff --git a/vendor/github.com/mattn/go-sqlite3/sqlite3_libsqlite3.go b/vendor/github.com/mattn/go-sqlite3/sqlite3_libsqlite3.go
index 135863e..9550d2f 100644
--- a/vendor/github.com/mattn/go-sqlite3/sqlite3_libsqlite3.go
+++ b/vendor/github.com/mattn/go-sqlite3/sqlite3_libsqlite3.go
@@ -9,6 +9,7 @@ package sqlite3
 /*
 #cgo CFLAGS: -DUSE_LIBSQLITE3
 #cgo linux LDFLAGS: -lsqlite3
+#cgo openbsd LDFLAGS: -lsqlite3
 #cgo darwin LDFLAGS: -L/usr/local/opt/sqlite/lib -lsqlite3
 */
 import "C"
diff --git a/vendor/github.com/mattn/go-sqlite3/sqlite3_load_extension.go b/vendor/github.com/mattn/go-sqlite3/sqlite3_load_extension.go
index 55c8ad7..e6e0801 100644
--- a/vendor/github.com/mattn/go-sqlite3/sqlite3_load_extension.go
+++ b/vendor/github.com/mattn/go-sqlite3/sqlite3_load_extension.go
@@ -7,7 +7,11 @@
 package sqlite3

 /*
+#ifndef USE_LIBSQLITE3
 #include <sqlite3-binding.h>
+#else
+#include <sqlite3.h>
+#endif
 #include <stdlib.h>
 */
 import "C"
diff --git a/vendor/github.com/mattn/go-sqlite3/sqlite3ext.h b/vendor/github.com/mattn/go-sqlite3/sqlite3ext.h
index f02f2c2..d89509f 100644
--- a/vendor/github.com/mattn/go-sqlite3/sqlite3ext.h
+++ b/vendor/github.com/mattn/go-sqlite3/sqlite3ext.h
@@ -17,7 +17,11 @@
 */
 #ifndef _SQLITE3EXT_H_
 #define _SQLITE3EXT_H_
-#include "sqlite3-binding.h"
+#ifndef USE_LIBSQLITE3
+#include <sqlite3-binding.h>
+#else
+#include <sqlite3.h>
+#endif

 typedef struct sqlite3_api_routines sqlite3_api_routines;

Whats your opinion on this topic?
I think warnings should be avoided, since they might confuse the user.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions