Help with sqlite

420 views
Skip to first unread message

rma...@gmail.com

unread,
Apr 14, 2011, 9:37:56 AM4/14/11
to golan...@googlegroups.com
Hi all,

I am using the gosqlite package (http://code.google.com/p/gosqlite/) which works and compiles just fine on my system, and I can build a program that pulls information out of sqlite3 databases.  The problem I am having is when I put my program on to the server it needs to run. It's Red Hat, and uses an older version of sqlite3.  When I run the program I get the following:

[user@server ~]$ ./mydb_report: symbol lookup error: ./mydb_report: undefined symbol: sqlite3_threadsafe

[user@server ~]$ sqlite3 -version
3.3.6

Anything I can do as I spent a day writing this and need to be able to run the report on the server, not on my local machine. 

Sven Engelhardt

unread,
Apr 14, 2011, 9:47:28 AM4/14/11
to golan...@googlegroups.com, rma...@gmail.com
I'd guess you'll need to compile your sqlite lib with SQLITE_THREADSAFE=1

ffs. http://www.sqlite.org/faq.html#q6

-Sven

2011/4/14 <rma...@gmail.com>:

rma...@gmail.com

unread,
Apr 14, 2011, 10:00:07 AM4/14/11
to golan...@googlegroups.com, rma...@gmail.com
On that server I don't have the privileges to install / compile any software.  I was hoping for a way to statically compile the sqlite library into my executable.

HaWe

unread,
Apr 14, 2011, 10:47:31 AM4/14/11
to golang-nuts
I had similar problems on my Debian/Lenny-System (with an old version
of sqlite).
Here is what helped me:
1. Clone the gosqlite archive with: hg clone ...
2. Use the version before january with: hg update -r 6
3. gomake
4. gomake install

rma...@gmail.com

unread,
Apr 14, 2011, 11:41:39 AM4/14/11
to golan...@googlegroups.com
Thanks, but that didn't seem to work... I ran the hg update -r

[rmasci@easnra ~]$  cd hg
[rmasci@easnra hg]$ hg update -r6
2 files updated, 0 files merged, 0 files removed, 0 files unresolved

Then make, make install. I then recompiled my application and copied it over to the server I need to run it on and I saw the same error.

HaWe

unread,
Apr 14, 2011, 1:30:10 PM4/14/11
to golang-nuts
Sorry, that I couldn't help. Maybe s.o. else has an idea.
Message has been deleted

rma...@gmail.com

unread,
Apr 14, 2011, 2:19:54 PM4/14/11
to golan...@googlegroups.com
The server this is running against is running Red Hat 5.3, which is my company's standard Linux install. I tried creating a go installation on this server, and compiling gosqlite fails:

[user@myserver sqlite]$ cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 5.3 (Tikanga)
[user@myserver sqlite]$ make
CGOPKGPATH= cgo --  sqlite.go
touch _obj/_cgo_run
6g -o _go_.6  _obj/sqlite.cgo1.go _obj/_cgo_gotypes.go
6c -FVw -I/home/n1rmasci/go/pkg/linux_amd64 -I . -o "_cgo_defun.6" _obj/_cgo_defun.c
gcc -m64 -I . -g -fPIC -O2 -o _cgo_main.o -c   _obj/_cgo_main.c
gcc -m64 -I . -g -fPIC -O2 -o sqlite.cgo2.o -c   _obj/sqlite.cgo2.c
sqlite.go: In function '_cgo_949207f1712e_Cfunc_sqlite3_prepare_v2':
sqlite.go:309: warning: passing argument 5 of 'sqlite3_prepare_v2' from incompatible pointer type
gcc -m64 -I . -g -fPIC -O2 -o _cgo_export.o -c   _obj/_cgo_export.c
gcc -m64 -g -fPIC -O2 -o _cgo1_.o _cgo_main.o sqlite.cgo2.o _cgo_export.o -L/usr/local/lib/oeis -lsqlite3  
sqlite.cgo2.o: In function `_cgo_949207f1712e_Cfunc_sqlite3_threadsafe':
/home/n1rmasci/go/src/pkg/sqlite/sqlite.go:319: undefined reference to `sqlite3_threadsafe'
sqlite.cgo2.o: In function `_cgo_949207f1712e_Cfunc_sqlite3_prepare_v2':
/home/n1rmasci/go/src/pkg/sqlite/sqlite.go:309: undefined reference to `sqlite3_prepare_v2'
sqlite.cgo2.o: In function `_cgo_949207f1712e_Cfunc_sqlite3_open_v2':
/home/n1rmasci/go/src/pkg/sqlite/sqlite.go:273: undefined reference to `sqlite3_open_v2'
sqlite.cgo2.o: In function `_cgo_949207f1712e_Cfunc_sqlite3_backup_pagecount':
/home/n1rmasci/go/src/pkg/sqlite/sqlite.go:246: undefined reference to `sqlite3_backup_pagecount'
sqlite.cgo2.o: In function `_cgo_949207f1712e_Cfunc_sqlite3_backup_remaining':
/home/n1rmasci/go/src/pkg/sqlite/sqlite.go:163: undefined reference to `sqlite3_backup_remaining'
sqlite.cgo2.o: In function `_cgo_949207f1712e_Cfunc_sqlite3_backup_step':
/home/n1rmasci/go/src/pkg/sqlite/sqlite.go:117: undefined reference to `sqlite3_backup_step'
sqlite.cgo2.o: In function `_cgo_949207f1712e_Cfunc_sqlite3_backup_finish':
/home/n1rmasci/go/src/pkg/sqlite/sqlite.go:104: undefined reference to `sqlite3_backup_finish'
sqlite.cgo2.o: In function `_cgo_949207f1712e_Cfunc_sqlite3_backup_init':
/home/n1rmasci/go/src/pkg/sqlite/sqlite.go:93: undefined reference to `sqlite3_backup_init'
collect2: ld returned 1 exit status
make: *** [_cgo1_.o] Error 1
[user@myserver sqlite]$ cat Makefile 
# Copyright 2010 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

include $(GOROOT)/src/Make.inc

TARG=sqlite

CGOFILES=\
sqlite.go

ifeq ($(GOOS),darwin)
CGO_LDFLAGS=/usr/lib/libsqlite3.0.dylib
else
CGO_LDFLAGS=-L/usr/local/lib/oeis -lsqlite3 
endif

include $(GOROOT)/src/Make.pkg
[user@myserver sqlite]$

The only thing is I changed from the original Makefile is the TARG.

There are a lot of applications that depend upon sqlite on the server I have to run my report on so I am hesitant to upgrade the version of sqlite. What I did to fix it was to compile the latest version of sqlite. I then had an administrator put the new compiled sqlite in /usr/local/sqlite.  I then had the administrator create an /etc/ld.so.conf.d/mysql_report.conf that contained one line: /usr/local/sqlite/lib, and then he ran ldconfig.  Now the system looks in /usr/local/sqlite/lib when my application is run.  

This is very ugly workaround, so I am hoping someone will have a better solution.

Russ Cox

unread,
Apr 14, 2011, 11:54:02 PM4/14/11
to golan...@googlegroups.com, rma...@gmail.com
I don't see why this workaround is so bad.
You can shorten it to just copying
an sqlite.so file next to your 6.out and then running

LD_LIBRARY_PATH=. 6.out

rma...@gmail.com

unread,
Apr 19, 2011, 12:13:11 PM4/19/11
to golan...@googlegroups.com, rma...@gmail.com
Is it possible to set an environment variable before importing?

os.Setenv("LD_LIBRARY_PATH","/usr/local/sqlite3/lib")
import "sqlite"

I passed a -L/usr/local/sqlite3/lib to cgo in order to compile sqlite, could cgo pick up on this somehow and use that location for when it has to load the library upon runtime?

Russ Cox

unread,
Apr 19, 2011, 2:11:36 PM4/19/11
to golan...@googlegroups.com, rma...@gmail.com

Use 6l -r /usr/local/sqlite3/lib

rma...@gmail.com

unread,
Apr 19, 2011, 3:45:03 PM4/19/11
to golan...@googlegroups.com, rma...@gmail.com, r...@golang.org
Ugh... I don't know if it's just me but... 

panic: runtime error: invalid memory address or nil pointer dereference

[signal 0xb code=0x1 addr=0x38 pc=0x420b97]

runtime.panic+0xac /usr/local/go/src/pkg/runtime/proc.c:1034
runtime.panic(0x471e28, 0xf840001440)
runtime.panicstring+0xa3 /usr/local/go/src/pkg/runtime/runtime.c:116
runtime.panicstring(0x4dba1f, 0x3)
runtime.sigpanic+0x144 /usr/local/go/src/pkg/runtime/linux/thread.c:292
runtime.sigpanic()
sqlite.*Stmt·Exec+0xe7 /usr/local/go/src/pkg/sqlite/_obj/sqlite.cgo1.go:-182
sqlite.*Stmt·Exec(0x0, 0xf840000138, 0x0, 0xf84001fcb0, 0xf84000f4b0, ...)
main.main+0xaaf /home/btadm/rich/main.go:91
main.main()
runtime.mainstart+0xf /usr/local/go/src/pkg/runtime/amd64/asm.s:77
runtime.mainstart()
runtime.goexit /usr/local/go/src/pkg/runtime/proc.c:178
runtime.goexit()

Russ Cox

unread,
Apr 19, 2011, 5:02:45 PM4/19/11
to golan...@googlegroups.com, rma...@gmail.com
> panic: runtime error: invalid memory address or nil pointer dereference

This means you dereferenced a nil pointer.

> main.main+0xaaf /home/btadm/rich/main.go:91

This says the line in your program that started the
chain that caused the nil pointer dereference.
If you look at that line you will probably find that
you called stmt.Exec(...) for stmt == nil.

Russ

Reply all
Reply to author
Forward
0 new messages