asg017 / sqlite-vss

A SQLite extension for efficient vector search, based on Faiss!
MIT License
1.59k stars 58 forks source link

Build fails on macOS: `Could NOT find OpenMP_C` #87

Open snej opened 11 months ago

snej commented 11 months ago

Trying to build on my MacBook Pro with M1 Pro CPU, macOS 13.4.1. I get as far as make loadable.

Looks like faiss expects the library OpenMP to be installed. HomeBrew doesn't seem to have it; the closest-named formulae are libopenmpt and open-mpi, neither of which are correct. The OpenMP website has a long list of tools and I have no idea which is relevant.

$  make loadable
mkdir -p dist/debug
mkdir -p dist/release
cmake -B build; make -C build
-- The C compiler identification is AppleClang 14.0.3.14030022
-- The CXX compiler identification is AppleClang 14.0.3.14030022
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /opt/homebrew/Cellar/cmake/3.26.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.26.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  /opt/homebrew/Cellar/cmake/3.26.4/share/cmake/Modules/FindOpenMP.cmake:577 (find_package_handle_standard_args)
  vendor/faiss/faiss/CMakeLists.txt:253 (find_package)
snej commented 11 months ago

OK, there is a HomeBrew package for faiss, and while it was installing, I saw openmpc as a dependency being installed.

However, afterwards make loadable still fails in the same way.

snej commented 11 months ago

By using the test.yaml workflow as a cheat sheet I was able to get it to work. It's basically:

brew install llvm libomp   # for some reason this step is missing from build-macos-aarch64-extension, but it's in x86
make patch-openmp
export CC=/opt/homebrew/opt/llvm/bin/clang
export CXX=/opt/homebrew/opt/llvm/bin/clang++
export CPPFLAGS=-I/opt/homebrew/include
export LDFLAGS="-L/opt/homebrew/lib -L/opt/homebrew/opt/libomp/lib"
make loadable static

It doesn't seem like LLVM's Clang should be required, instead of the one from Apple's dev tools, but if I don't set CC and CXX the build fails as I originally reported. Probably something to do with search paths, but adding CFLAGS=-I/opt/homebrew/include doesn't help.