Uh oh!
There was an error while loading. Please reload this page.
Use autolinking on Apple platforms to prevent the need to link with sqlite3 explicitly - #120
Use autolinking on Apple platforms to prevent the need to link with sqlite3 explicitly#120timofeys1 wants to merge 2 commits into
Conversation
Such failure happens when K/N produces a library archive of a static framework and the linkage happens outside, for example as part of an Xcode build process.
kpgalligan
commented
Mar 19, 2024
That's an interesting option. We'd need to figure out how to use things like sqlcipher in this context, which is a "drop-in" replacement for the system sqlite library. Will have to look at this in more detail, though. |
timofeys1
commented
Mar 20, 2024
Disabling default search paths via // main.c#include"sqlite3.h"intmain(void) {
sqlite3_sourceid();
}and a custom implementation: // my_sqlite3.cconstchar*sqlite3_sourceid(void) { return"foo"; }one could: # Compile main
clang -Xclang --linker-option=-lsqlite3 -c main.c -o main.o
# Default option: link against system's sqlite3
clang main.o -o mainSystem && otool -L mainSystem | grep sqlite
# Compile and link custom sqlite3 dylib
mkdir dylib
clang my_sqlite3.c -dynamiclib -o "$(realpath dylib)"/libsqlite3.dylib
# Link against custom sqlite3
clang -Z -Ldylib -L/usr/lib main.o -o mainCustom && otool -L mainCustom | grep sqlite |
timofeys1
commented
Oct 4, 2024
Hi Kevin. Were you able to look into this PR? Perhaps implementing autolinking and linking against a custom sqlite3 version could be achieved in a simpler way than what I originally suggested. I think it is sufficient to add When producing a framework:
I believe in case you need to link against a custom |
kpgalligan
commented
Oct 5, 2024
I was not. It is an interesting option, but the overall todo list is rather long (outside of SQLiter). I'll bump it back up, but there are follow-on considerations, and other conversations happening concurrently.
So, in summary, it's on the radar, but it's complicated :) |
On Apple platforms an explicit linking configuration is usually not required, because
clangandswiftccompilers embed linker commands into.ofiles they produce. These linker commands can be printed out viaotool -l /path/to/object | grep -A 4 LC_LINKER_OPTION.This MR uses this technique to remove the requirement to explicitly link with
-lsqlite3on Apple platforms by embeddingLC_LINKER_OPTIONcommand into object files produced by K/N. This may be most useful for projects that link against K/N static libraries in Xcode, but should also remove the need for consumer side linker configuration.As an integration test, I disabled explicit linking in sqldelight and ran the tests I could find against this MR: 1, 2