Skip to content

Link the CLI's libraries after its archives - #22

Merged
vlasky merged 1 commit into
vlasky:mainfrom
MayCXC:cli-link-order-vlasky
Oct 28, 2026
Merged

vlasky merged 1 commit into
vlasky:mainfrom
MayCXC:cli-link-order-vlasky

Conversation

@MayCXC

@MayCXC MayCXC commented Oct 23, 2026 •

Copy link
Copy Markdown

make cli fails to link on Linux:

$ ./scripts/vendor.sh && make cli
...
sqlite-vec.c:418:(.text+0x430): undefined reference to `sqrt'
...
collect2: error: ld returned 1 exit status

The CLI rule passes -ldl -lm before core_init.c and the .a archives. GNU ld resolves symbols left to right, so by the time it reads sqlite-vec.a, libm has already been passed over, and the archive's calls to sqrt (6), ceil (2) and pow (1) stay unresolved. macOS's linker does not depend on the order, and the release workflow builds the CLI only with cosmocc, so CI never hits it.

This PR moves -ldl -lm after the archives, the order photostructure/sqlite-vec@9db2489 uses. Upstream, asg017#281 makes this same change to the CLI rule, and asg017#304 moves the link libraries after the inputs on every link line.

Test. On Linux arm64 with GCC 14, make cli on main fails as above; on this branch it builds dist/sqlite3, which runs select vec_version() and a KNN query over a vec0 table. It merges cleanly with #9 to #14 and #17 to #21.

GNU ld resolves symbols left to right, so with -ldl -lm ahead of the
archives, the sqrt, pow and ceil calls in sqlite-vec.a went unresolved and
make cli failed on Linux. photostructure/sqlite-vec@9db2489 links the
libraries last; asg017#304 does the same upstream.
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

Successfully merging this pull request may close these issues.

2 participants