Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to link under Linux #48

Closed
teras opened this issue Sep 27, 2023 · 7 comments
Closed

Unable to link under Linux #48

teras opened this issue Sep 27, 2023 · 7 comments

Comments

@teras
Copy link

teras commented Sep 27, 2023

Hello
I am trying to use SQLlin in Kotlin/Native Linux x64 platform.
Unfortunately it breaks with an error:


The /home/teras/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold command returned non-zero exit code: 1.
output:
/home/teras/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold: error: cannot find -lsqlite3
/tmp/konan_temp4860865497063593644/result.o:out:function com_ctrip_sqllin_sqlite3_sqlite3_close_v2_wrapper7: error: undefined reference to 'sqlite3_close_v2'
/tmp/konan_temp4860865497063593644/result.o:out:function com_ctrip_sqllin_sqlite3_sqlite3_exec_wrapper8: error: undefined reference to 'sqlite3_exec'
...

plus a huge list of unresolved references to sqlite functions.

Of course, I do have sqlite installed

$ ls -l /usr/lib/libsqlite3.so 
lrwxrwxrwx root root 19 B Mon Sep 11 20:45:28 2023  /usr/lib/libsqlite3.so ⇒ libsqlite3.so.0.8.6

so the problem must be something else.
Any idea?

@qiaoyuang
Copy link
Collaborator

Did your Linux executable program project add the linkerOpts into your build.gradle.kts correctly?

@teras
Copy link
Author

teras commented Sep 28, 2023

I was following the documentation to the letter. Are there any options I should put?
The interesting part is that the library itself added the -lsqlite3 option, not me.

@qiaoyuang
Copy link
Collaborator

Try adding this line to your build.gradle.kts executable program project:

linkerOpts += listOf("-lsqlite3", "-L/usr/lib")

If that doesn't work, try using the libsqlite3.a to replace your libsqlite3.so file.

@teras
Copy link
Author

teras commented Sep 28, 2023

This improved the situation, but I have another problem now:
(The error list is exhaustive)

The /home/teras/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold command returned non-zero exit code: 1.
output:
/usr/lib/libsqlite3.so: error: undefined reference to 'fmod', version 'GLIBC_2.38'
/usr/lib/libsqlite3.so: error: undefined reference to 'fcntl64', version 'GLIBC_2.28'
/usr/lib/libsqlite3.so: error: undefined reference to 'fstat64', version 'GLIBC_2.33'
/usr/lib/libsqlite3.so: error: undefined reference to 'log', version 'GLIBC_2.29'
/usr/lib/libsqlite3.so: error: undefined reference to 'dlerror', version 'GLIBC_2.34'
/usr/lib/libsqlite3.so: error: undefined reference to 'pthread_mutexattr_destroy', version 'GLIBC_2.34'
/usr/lib/libsqlite3.so: error: undefined reference to 'stat64', version 'GLIBC_2.33'
/usr/lib/libsqlite3.so: error: undefined reference to 'dlopen', version 'GLIBC_2.34'
/usr/lib/libsqlite3.so: error: undefined reference to 'exp', version 'GLIBC_2.29'
/usr/lib/libsqlite3.so: error: undefined reference to 'pthread_join', version 'GLIBC_2.34'
/usr/lib/libsqlite3.so: error: undefined reference to 'pthread_mutexattr_init', version 'GLIBC_2.34'
/usr/lib/libsqlite3.so: error: undefined reference to 'pthread_mutexattr_settype', version 'GLIBC_2.34'
/usr/lib/libsqlite3.so: error: undefined reference to 'pthread_create', version 'GLIBC_2.34'
/usr/lib/libsqlite3.so: error: undefined reference to 'pow', version 'GLIBC_2.29'
/usr/lib/libsqlite3.so: error: undefined reference to 'pthread_mutex_trylock', version 'GLIBC_2.34'
/usr/lib/libsqlite3.so: error: undefined reference to 'dlclose', version 'GLIBC_2.34'
/usr/lib/libsqlite3.so: error: undefined reference to 'dlsym', version 'GLIBC_2.34'
/usr/lib/libsqlite3.so: error: undefined reference to 'log2', version 'GLIBC_2.29'
/usr/lib/libsqlite3.so: error: undefined reference to 'lstat64', version 'GLIBC_2.33'

@qiaoyuang
Copy link
Collaborator

qiaoyuang commented Sep 28, 2023

Try to use the libsqlite3.a to replace your libsqlite3.so under the same directory.

@teras
Copy link
Author

teras commented Oct 2, 2023

Hello

First of all, asking to link statically shouldn't be a proper solution. There are reasons why dynamic libraries are present. Especially if we override system files, like /usr/lib/*.so.

Having said that, I found a solution which probably should be documented somewhere. In order for linking to work, linker should be more relaxed. So instead of only linkerOpts += listOf("-lsqlite3", "-L/usr/lib") as parameters, the parameter --allow-shlib-undefined is also required.

Final list of parameters is:

 linkerOpts += mutableListOf("-lsqlite3", "-L/usr/lib", "--allow-shlib-undefined")

@qiaoyuang
Copy link
Collaborator

OK, thank you. That's good. I will modify related documents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants