Cross-Compile sqlite3 package for node

I am using Ubuntu 16.04 with Node 4.6.1 and NPM 2.15.9 to cross compile sqlite3(with sqlcipher support) for Colibri-iMX6. I have the same node version on Ubuntu and Embedded Linux (morty). I have sqlite3 installed in the Linux Image as well as SDK.

I started out with exporting the environment variables from SDK. First, I cross-compiled OpenSSL 1.0.2 followed by Sqlcipher. I got a static library from sqlcipher (libsqlcipher.a) whose path is exported to the LDFLAGS.

I am using the following command to cross compile:

npm install sqlite3 --target_arch=arm --enable-static=yes --build-from-source --sqlite_libname=sqlcipher -fPIC --sqlite=home/onkar/Library/sqlcipher-master/.libs --verbose

The error I get while cross compiling is as follows:

/home/onkar/linuximage/sdk/sysroots/x86_64-angstromsdk-linux/usr/libexec/arm-angstrom-linux-gnueabi/gcc/arm-angstrom-linux-gnueabi/5.2.1/real-ld: error: /home/onkar/Library/sqlcipher-master/.libs/libsqlcipher.a(sqlite3.o): requires unsupported dynamic reloc R_ARM_THM_MOVW_ABS_NC; recompile with -fPIC 
collect2: error: ld returned 1 exit status
node_sqlite3.target.mk:129: recipe for target 'Release/obj.target/node_sqlite3.node' failed
make: *** [Release/obj.target/node_sqlite3.node] Error 1
make: Leaving directory '/home/onkar/node_modules/sqlite3/build'

Can someone please help me resolve this error ?

Thanks,

Onkar

Hi Onkar

Have you tried to build it with openembedded, e.g. by adding one of these layers?


/home/onkar/linuximage/sdk/sysroots/x86_64-angstromsdk-linux/usr/libexec/arm-angstrom-linux-gnueabi/gcc/arm-angstrom-linux-gnueabi/5.2.1/real-ld: error: /home/onkar/Library/sqlcipher-master/.libs/libsqlcipher.a(sqlite3.o): requires unsupported dynamic reloc R_ARM_THM_MOVW_ABS_NC; recompile with -fPIC 

You seem to use a SDK from OE. This may (or may not) be solved when using the bfd linker.
e.g.

ls <path to SDK>/sysroots/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-ld* -l

shows that arm-angstrom-linux-gnueabi-ld and arm-angstrom-linux-gnueabi-ld.gold are currently the same.
Copy arm-angstrom-linux-gnueabi-ld.bfd to arm-angstrom-linux-gnueabi-ld to get the bfd linker to be the default.

This may (or may not) be solved compiling with -fPIC.
e.g. before compiling change the CFLAGS or CXXFLAGS set up by sourcing the SDK environment script:

$ export CFLAGS="$CFLAGS -fPIC"
$ export CXXFLAGS="$CXXFLAGS -fPIC"
$ echo $CFLAGS
-O2 -pipe -g -feliminate-unused-debug-types -fPIC

Max