Hello I have been evaluating nim, I was playing around when i encountering few things that i would like to resolve. Thanks in advance for the help.
I have a problem trying to run the following simple code:
import db_sqlite
let conn = open("mydb.sql", nil, nil, nil)
conn.close();
I compile it using the following command:
nim -d:release c src/service.nim
compiles OK when i execute the binary the following appears:
could not load: libsqlite3.so(|.0)
compile with -d:nimDebugDlOpen for more information
So i guess is doing dlopen to find the libsqlite3.so, what about if i want to link sqlite3 statically? can I pass sqlite3.c (amalgamated) in some way? , cant find an option to do so or anything related.
things i have tried:
$ nim -d:nimDebugDlOpen --passL:sqlite.a c src/service.nim
Hint: used config file '/nix/store/q39xgpzqqdx8bc76bxsl6vxrl6sagi49-nim-0.18.0/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: service [Processing]
Hint: db_sqlite [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: algorithm [Processing]
Hint: sqlite3 [Processing]
Hint: db_common [Processing]
Hint: [Link]
sqlite.a: In function `pthreadMutexAlloc':
sqlite3.c:(.text+0x1d683): undefined reference to `pthread_mutexattr_init'
sqlite3.c:(.text+0x1d690): undefined reference to `pthread_mutexattr_settype'
sqlite3.c:(.text+0x1d6a3): undefined reference to `pthread_mutexattr_destroy'
sqlite.a: In function `pthreadMutexTry':
sqlite3.c:(.text+0x1d7a2): undefined reference to `pthread_mutex_trylock'
sqlite.a: In function `vdbeSorterJoinThread':
sqlite3.c:(.text+0x347c7): undefined reference to `pthread_join'
sqlite.a: In function `vdbeSorterFlushPMA':
sqlite3.c:(.text+0x507e1): undefined reference to `pthread_create'
sqlite.a: In function `vdbePmaReaderIncrInit':
sqlite3.c:(.text+0x55979): undefined reference to `pthread_create'
sqlite.a: In function `vdbePmaReaderNext':
sqlite3.c:(.text+0x5657e): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
Error: execution of an external program failed: 'gcc -o /home/pvd/Devel/nim/src/service /home/pvd/Devel/nim/src/nimcache/service_service.o /home/pvd/Devel/nim/src/nimcache/stdlib_system.o /home/pvd/Devel/nim/src/nimcache/stdlib_db_sqlite.o /home/pvd/Devel/nim/src/nimcache/stdlib_strutils.o /home/pvd/Devel/nim/src/nimcache/stdlib_parseutils.o /home/pvd/Devel/nim/src/nimcache/stdlib_math.o /home/pvd/Devel/nim/src/nimcache/stdlib_algorithm.o /home/pvd/Devel/nim/src/nimcache/stdlib_sqlite3.o /home/pvd/Devel/nim/src/nimcache/stdlib_db_common.o -lm sqlite.a -ldl'
~/D/nim gcc
gcc: fatal error: no input files
compilation terminated.
Some kind related to my problem:
how do I compile in release/debug/releaseWithSymbols.... with nimble? the only option i have is 'nimble build'
I also tried:
nim -d:nimDebugDlOpen --dynlibOverride:sqlite --passl:sqlite.a --threads:on c src/service.nim
with no luck
I am a newbie, but I had a similar problems which was fixed by the awesome community.
Sorry yatesco, I have no idea how your docker cross-compile problem may be related to above question.
From the compiler error message libsqlite3 lib seems to be missing, maybe not installed at all, in wrong path, with other name. So maybe someone familiar with sqlite should try to help.
@pavil You need to install the sqlite librayr on your system. I assume you're running on Linux, judging by your error emssages. It depends on the distribution you use, but for Debian you will need to install the libsqlite3-dev package:
apt install libsqlite3-dev
I've never tried to static link to SQLite before, I've always just relied on having the required packages on the target system.
You can also add this requirement to your program's .nimble file too by adding something like this:
when defined(nimdistros):
import distros
if detectOs(Debian) or detectOs(Ubuntu):
foreignDep "libsqlite3-dev"
else:
foreignDep "libsqlite3"
For some documentation on this feature, please see here.