I'm new to Gyp. Instead of compiling my dependency, I would like to use a shared library, in particular, the libsqlite3.so which is already on my machine. The main binding.gyp currently looks like
{
'targets': [
{
'target_name': 'node_sqlite3',
'sources': [
'src/database.cc',
'src/node_sqlite3.cc',
'src/statement.cc'
],
'dependencies': [
'deps/sqlite3/binding.gyp:sqlite3'
]
}
]
}
How do I change this so that a shared sqlite3 library is used? The binding.gyp in the deps folder has a section that looks like below. I don't think I need gyp to do any compilation of sqlite3 for me, so switching type to shared_library is probably not the right answer.
'targets': [
{
'target_name': 'sqlite3',
'type': 'static_library',
'include_dirs': [ '.' ],
'direct_dependent_settings': {
'include_dirs': [ '.' ],
'defines': [
'SQLITE_THREADSAFE=1',
'SQLITE_ENABLE_FTS3',
'SQLITE_ENABLE_RTREE'
],
},
'defines': [
'_REENTRANT=1',
'SQLITE_THREADSAFE=1',
'SQLITE_ENABLE_FTS3',
'SQLITE_ENABLE_RTREE'
],
'sources': [ './sqlite3.c', ],
},
{
'target_name': 'shell',
'type': 'executable',
'dependencies': [ 'sqlite3' ],
'sources': [ './shell.c' ]
}
]
}
Update. I was able to get things to compile by changing by binding.gyp to this
{
'targets': [
{
'target_name': 'node_sqlite3',
'sources': [
'src/database.cc',
'src/node_sqlite3.cc',
'src/statement.cc'
],
'ldflags': [
'-lsqlite3'
]
}
]
}
However, when I go to run a program using the module, I get
node: symbol lookup error: /usr/local/lib/node_modules/sqlite3/build/Release/node_sqlite3.node: undefined symbol: sqlite3_open_v2
as if the shared library is not loading or is not accessible. I think I'm close. libsqlite3 was installed to /usr/local/lib
/usr/local/lib$ ls libsqlite3.a libsqlite3.so libsqlite3.so.0.8.6 node_modules python2.7 libsqlite3.la libsqlite3.so.0 node pkgconfig
Update2. The plot thickens. I tried ldd on the executable created by node-sqlite3
linux-vdso.so.1 => (0x00007fffd7168000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fc9451df000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc944fc2000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc944c04000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc94490a000) /lib64/ld-linux-x86-64.so.2 (0x00007fc945704000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc9446f4000)
Clearly missing libsqlite3. So perhaps my ldflags statement did not really work as planned.
Node SQLite3 : This is a node.js driver for SQLite3. It is written in JavaScript, does not require compiling. It provides all most all connection/query from SQLite3. Node-sqlite3 is probably one of the best modules used for working with SQLite3 database which is actively maintained and well documented.
The sqlite3 module works with Node.js v0.10.x or v0.11.x (though only v0.11.13 and above). Binaries for most Node versions and platforms are provided by default via node-pre-gyp. Node-sqlite3 has built-in function call serialization and automatically waits before executing a blocking action until no other action is pending.
To mitigate this problem, node-sqlite3 has a verbose mode which captures stack traces when enqueuing queries. To enable this mode, call the sqlite3.verbose (), or call it directly when requiring: var sqlite3 = require ('sqlite3').verbose ().
Node-sqlite3 has built-in function call serialization and automatically waits before executing a blocking action until no other action is pending. This means that it's safe to start calling functions on the database object even if it is not yet fully opened.
Here's the answer.
{
'targets': [
{
'target_name': 'node_sqlite3',
'sources': [
'src/database.cc',
'src/node_sqlite3.cc',
'src/statement.cc'
],
'link_settings': {
'libraries': [
'-lsqlite3'
]
}
}
]
}
Upon use of ldd:
~/node-sqlite3/build/Release$ ldd node_sqlite3.node linux-vdso.so.1 => (0x00007fffe9548000) > libsqlite3.so.0 => /usr/local/lib/libsqlite3.so.0 (0x00007f6649504000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f66491ff000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f6648fe1000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6648c24000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6648a20000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6648725000) /lib64/ld-linux-x86-64.so.2 (0x00007f66499cd000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f664850f000)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With