SQLite User Forum

Undefined symbol when compiling a loadable library
Login

Undefined symbol when compiling a loadable library

(1) By ingo on 2022-11-15 07:43:43 [source]

When trying to compile the array library from sqlean on FreeBSD I run into trouble. It compiles, but when I load the library it errors with Undefined symbol "arrayscalar_init" I have no idea what this means (utter lack of experience). Doing the same on windows works fine. What am I doing wrong?

I used:

FreeBSD sqlite 3.39.3

https://sqlite.org/2022/sqlite-amalgamation-3390300.zip

$ cc -fPIC -shared -I./array/*.c array.c -o array.so

drwxr-xr-x  3       11 Nov  8 19:26 ./
drwxr-xr-x  4        4 Nov  8 14:51 ../
drwxr-xr-x  2        8 Nov  8 14:42 array/
-rw-r--r--  1      620 Sep 20 14:20 array.c
-rwxr-xr-x  1    25512 Nov  8 19:26 array.so*
-rw-r--r--  1   734131 Sep 29 18:01 shell.c
-rw-r--r--  1  8550097 Sep 29 18:01 sqlite3.c
-rw-r--r--  1   613416 Sep 29 18:01 sqlite3.h
-rw-r--r--  1    37310 Sep 29 18:01 sqlite3ext.h

sqlite> .load ./array
Error: ./array.so: Undefined symbol "arrayscalar_init"

(2) By Larry Brasfield (larrybr) on 2022-11-15 07:56:09 in reply to 1 [link] [source]

The symbol is defined in the file src/array/scalar.c . It is used in the array.c that you attempted to compile and link.

It looks like this project is not meant to be used with one-line compiles. You need to see how it is normally built, and emulate that to a greater extent.

(3) By ingo on 2022-11-15 08:26:21 in reply to 2 [link] [source]

Thank you!

from the makefile:

make compile-linux-extension name=array src="src/array/*.c"

gcc -fPIC -shared -Isrc src/$(name).c $(src) -o dist/$(name).so $(args)

source = ./array/*.c gives:

cc -fPIC -shared -I./array/*.c array.c ./array/*.c -o array.so

and then the library loads without error.