Cross Compile SqliCipher for arm

Hi,

I am trying to cross compile sqlcipher for linux based arm processor. I am using Ubuntu to cross compile.

I have cross-compiled openssl to the arm architecture and using the static library to link against.

I have set the CC environment variable to point to cross-compiler gcc

I use the following command to compile.
$./configure --host=arm --enable-static=yes --enable-tempstore=yes CFLAGS=“-DSQLITE_HAS_CODEC” LDFLAGS=“/path/to/libcrypto/libcrypto.a”

I get the following output from config.

checking build system type… x86_64-unknown-linux-gnu
checking host system type… arm-unknown-none
checking how to print strings… printf
checking for arm-gcc… /gcc-linaro/bin/arm-linux-gnueabihf-gcc
checking whether the C compiler works… yes
checking for C compiler default output file name… a.out
checking for suffix of executables…
checking whether we are cross compiling… yes
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether /gcc-linaro/bin/arm-linux-gnueabihf-gcc accepts -g… yes
checking for /gcc-linaro/bin/arm-linux-gnueabihf-gcc option to accept ISO C89… none needed
checking for a sed that does not truncate output… /bin/sed
checking for grep that handles long lines and -e… /bin/grep
checking for egrep… /bin/grep -E
checking for fgrep… /bin/grep -F
checking for ld used by /gcc-linaro/bin/arm-linux-gnueabihf-gcc… /gcc-linaro-5.2-2015.11-2-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/bin/ld
checking if the linker (/gcc-linaro-5.2-2015.11-2-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/bin/ld) is GNU ld… yes
checking for BSD- or MS-compatible name lister (nm)… no
checking for arm-dumpbin… no
checking for arm-link… no
checking for dumpbin… no
checking for link… link -dump
configure: WARNING: using cross tools not prefixed with host triplet
checking the name lister (nm) interface… BSD nm
checking whether ln -s works… yes
checking the maximum length of command line arguments… 1572864
checking how to convert x86_64-unknown-linux-gnu file names to arm-unknown-none format… func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format… func_convert_file_noop
checking for /gcc-linaro-5.2-2015.11-2-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/bin/ld option to reload object files… -r
checking for arm-objdump… no
checking for objdump… objdump
checking how to recognize dependent libraries… unknown
checking for arm-dlltool… no
checking for dlltool… no
checking how to associate runtime and link libraries… printf %s\n
checking for arm-ar… no
checking for ar… ar
checking for archiver @FILE support… @
checking for arm-strip… no
checking for strip… strip
checking for arm-ranlib… no
checking for ranlib… ranlib
checking for gawk… gawk
checking command to parse nm output from /gcc-linaro/bin/arm-linux-gnueabihf-gcc object… ok
checking for sysroot… no
checking for a working dd… /bin/dd
checking how to truncate binary pipes… /bin/dd bs=4096 count=1
checking for arm-mt… no
checking for mt… mt
checking if mt is a manifest tool… no
checking how to run the C preprocessor… /gcc-linaro/bin/arm-linux-gnueabihf-gcc -E
checking for ANSI C header files… yes
checking for sys/types.h… yes
checking for sys/stat.h… yes
checking for stdlib.h… yes
checking for string.h… yes
checking for memory.h… yes
checking for strings.h… yes
checking for inttypes.h… yes
checking for stdint.h… yes
checking for unistd.h… yes
checking for dlfcn.h… yes
checking for objdir… .libs
checking if /gcc-linaro/bin/arm-linux-gnueabihf-gcc supports -fno-rtti -fno-exceptions… no
checking for /gcc-linaro/bin/arm-linux-gnueabihf-gcc option to produce PIC… -fPIC -DPIC
checking if /gcc-linaro/bin/arm-linux-gnueabihf-gcc PIC flag -fPIC -DPIC works… yes
checking if /gcc-linaro/bin/arm-linux-gnueabihf-gcc static flag -static works… yes
checking if /gcc-linaro/bin/arm-linux-gnueabihf-gcc supports -c -o file.o… yes
checking if /gcc-linaro/bin/arm-linux-gnueabihf-gcc supports -c -o file.o… (cached) yes
checking whether the /gcc-linaro/bin/arm-linux-gnueabihf-gcc linker (/gcc-linaro-5.2-2015.11-2-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/bin/ld) supports shared libraries… yes
checking whether -lc should be explicitly linked in… no
checking dynamic linker characteristics… no
checking how to hardcode library paths into programs… immediate
checking whether stripping libraries is possible… yes
checking if libtool supports shared libraries… no
checking whether to build shared libraries… no
checking whether to build static libraries… yes
checking for a BSD-compatible install… /usr/bin/install -c
checking for special C compiler options needed for large files… no
checking for _FILE_OFFSET_BITS value needed for large files… 64
checking for int8_t… yes
checking for int16_t… yes
checking for int32_t… yes
checking for int64_t… yes
checking for intptr_t… yes
checking for uint8_t… yes
checking for uint16_t… yes
checking for uint32_t… yes
checking for uint64_t… yes
checking for uintptr_t… yes
checking for sys/types.h… (cached) yes
checking for stdlib.h… (cached) yes
checking for stdint.h… (cached) yes
checking for inttypes.h… (cached) yes
checking malloc.h usability… yes
checking malloc.h presence… yes
checking for malloc.h… yes
checking for fdatasync… yes
checking for gmtime_r… yes
checking for isnan… yes
checking for localtime_r… yes
checking for localtime_s… no
checking for malloc_usable_size… yes
checking for strchrnul… yes
checking for usleep… yes
checking for utime… yes
checking for pread… yes
checking for pread64… yes
checking for pwrite… yes
checking for pwrite64… yes
checking for tclsh8.6… tclsh8.6
configure: Version set to 3.15
configure: Release set to 3.15.2
configure: Version number set to 3015002
checking for gcc… gcc
checking whether to support threadsafe operation… yes
checking for library containing pthread_create… -lpthread
checking for library containing pthread_mutexattr_init… none required
checking for crypto library to use… openssl
checking for HMAC_Init_ex in -lcrypto… no
configure: error: Library crypto not found. Install openssl!"

Can someone let me know I am missing any Flags?

Hi @onkarmahajan

checking for HMAC_Init_ex in -lcrypto… no
configure: error: Library crypto not found. Install openssl!"

The ./configure script cannot locate a system install of OpenSSL. As you are providing your own build of OpenSSL, try passing --with-crypto-lib=none to ./configure, then pass -DSQLCIPHER_CRYPTO_OPENSSL with your CFLAGS.

Hey @developernotes

Thank you. The configure script works but when I run the make command I get an error that sqlite3.c cannot find openssl/rand.h.

sqlite3.c:20258:26: fatal error: openssl/rand.h: No such file or directory

I really appreciate your help.

Thanks,
Onkar

Hi @onkarmahajan

Your CFLAGS must also include the path to your OpenSSL include folder (i.e., -I/some/path/here).

Thanks @developernotes for the quick response.

For some reason, I am getting undefined references to the openssl library. I have provided a cross-compiled static library to LDFLAGS.

./configure --host=arm --enable-static=yes --with-crypto-lib=none --enable-tempstore=yes CFLAGS=“-DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -I/home/onkar/Downloads/openssl-1.0.2k/include” LDFLAGS=“/home/onkar/Downloads/openssl-1.0.2k/libcrypto.a”

The linker error I get is:

./.libs/libsqlcipher.a(sqlite3.o): In function HMAC_CTX_new': sqlite3.c:(.text+0x3034): undefined reference to CRYPTO_malloc’
sqlite3.c:(.text+0x3042): undefined reference to `HMAC_CTX_init’

Thanks,
Onkar