Skip to content

Fix link ordering so libm/pthread resolve in make all#304

Open
stumpylog wants to merge 1 commit into
asg017:mainfrom
stumpylog:fix/lib-linking
Open

Fix link ordering so libm/pthread resolve in make all#304
stumpylog wants to merge 1 commit into
asg017:mainfrom
stumpylog:fix/lib-linking

Conversation

@stumpylog

Copy link
Copy Markdown

Problem

On Linux, make all fails at link time:

undefined reference to `sqrt' / `pow' / `ceil'

-lm lives in CFLAGS, which is expanded before the archive inputs on each link line. GNU ld --as-needed (Debian/Ubuntu default) then drops libm before it reaches sqlite-vec.a. Same trap for libpthread (sqlite is built threadsafe but -lpthread is never linked).

Fixes #84, #93, #2.

Fix

Move link libraries out of CFLAGS into a dedicated LINK_LIBS appended after the inputs on every link line.

-CFLAGS += -lm
+LINK_LIBS += -lm -ldl -lpthread

Verification

make clean && make all                              # was failing, now exits 0
dist/sqlite3 :memory: "SELECT vec_version()"        # v0.1.10-alpha.4

Complementary to #290/#292, which add $(CFLAGS) to compile lines but don't touch the -lm link ordering.

@stumpylog stumpylog marked this pull request as ready for review June 11, 2026 13:59
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.

undefined reference to `sqrt'

1 participant