Skip to content

Commit c4bcfdc

Browse files
fix: improve glog detection and fix install permission issues
1. glog detection improvements: - Try find_package(glog) first - Fallback to pkg-config with proper LINK_LIBRARIES - Try direct library search in common paths - Final fallback to -lglog linker flag - Remove FATAL_ERROR to allow build to proceed 2. Fix third-party library install permissions: - Set CMAKE_INSTALL_PREFIX to local build/install directory - Prevents permission denied errors when installing to /usr/local - Applies to GTI, IP-DiskANN, and PLSH 3. Add ALGORITHMS_IMPL_DIR variable at script start - Used for local install prefix paths - Create build/install directory upfront This should fix both the 'glog not found' CMake error and the 'Permission denied' install errors.
1 parent 1a9440b commit c4bcfdc

2 files changed

Lines changed: 32 additions & 18 deletions

File tree

algorithms_impl/CMakeLists.txt

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,35 @@ if(TORCH_PYTHON_LIBRARY)
143143
endif()
144144

145145
# 必需: glog (必须在 DiskANN 之前,因为 DiskANN 依赖它)
146-
find_package(PkgConfig)
147-
if(PKG_CONFIG_FOUND)
148-
pkg_check_modules(GLOG libglog)
149-
if(GLOG_FOUND)
150-
list(APPEND PYCANDY_LIBS ${GLOG_LIBRARIES})
151-
message(STATUS "Found glog via pkg-config: ${GLOG_LIBRARIES}")
152-
else()
153-
find_library(GLOG_LIB glog)
146+
# 尝试多种方式查找 glog
147+
find_package(glog QUIET)
148+
if(glog_FOUND)
149+
list(APPEND PYCANDY_LIBS glog::glog)
150+
message(STATUS "Found glog via find_package")
151+
else()
152+
# 尝试使用 pkg-config
153+
find_package(PkgConfig QUIET)
154+
if(PKG_CONFIG_FOUND)
155+
pkg_check_modules(GLOG libglog QUIET)
156+
if(GLOG_FOUND)
157+
list(APPEND PYCANDY_LIBS ${GLOG_LINK_LIBRARIES})
158+
include_directories(${GLOG_INCLUDE_DIRS})
159+
message(STATUS "Found glog via pkg-config: ${GLOG_LINK_LIBRARIES}")
160+
endif()
161+
endif()
162+
163+
# 如果还是找不到,尝试直接查找库文件
164+
if(NOT GLOG_FOUND)
165+
find_library(GLOG_LIB glog PATHS /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu)
154166
if(GLOG_LIB)
155167
list(APPEND PYCANDY_LIBS ${GLOG_LIB})
156-
message(STATUS "Found glog: ${GLOG_LIB}")
168+
message(STATUS "Found glog library: ${GLOG_LIB}")
157169
else()
158-
message(FATAL_ERROR "glog not found - required for PyCANDYAlgo")
170+
# 最后的尝试:直接链接 -lglog
171+
list(APPEND PYCANDY_LIBS glog)
172+
message(WARNING "glog not found via find_package or pkg-config, linking with -lglog")
159173
endif()
160174
endif()
161-
else()
162-
find_library(GLOG_LIB glog REQUIRED)
163-
list(APPEND PYCANDY_LIBS ${GLOG_LIB})
164-
message(STATUS "Found glog: ${GLOG_LIB}")
165175
endif()
166176

167177
# 可选: aio

algorithms_impl/build.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
set -e # 遇到错误立即退出
55

6+
# 获取脚本所在目录的绝对路径
7+
ALGORITHMS_IMPL_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8+
69
echo "========================================="
710
echo "Building PyCANDYAlgo Module"
811
echo "========================================="
@@ -26,8 +29,9 @@ if [ -d "build" ]; then
2629
rm -rf build
2730
fi
2831

29-
# 创建构建目录
32+
# 创建构建目录和安装目录
3033
mkdir -p build
34+
mkdir -p build/install
3135
cd build
3236

3337
echo ""
@@ -236,7 +240,7 @@ if [ -d "gti/GTI" ]; then
236240
fi
237241
mkdir -p bin build
238242
cd build
239-
cmake -DCMAKE_BUILD_TYPE=Release .. || { echo "❌ GTI cmake failed"; exit 1; }
243+
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$ALGORITHMS_IMPL_DIR/build/install" .. || { echo "❌ GTI cmake failed"; exit 1; }
240244
make -j${JOBS} || { echo "❌ GTI build failed"; exit 1; }
241245
make install || echo " ⚠ GTI install failed (not critical)"
242246
cd ../../..
@@ -257,7 +261,7 @@ if [ -d "ipdiskann" ]; then
257261
fi
258262
mkdir -p build
259263
cd build
260-
cmake .. || { echo "❌ IP-DiskANN cmake failed"; exit 1; }
264+
cmake -DCMAKE_INSTALL_PREFIX="$ALGORITHMS_IMPL_DIR/build/install" .. || { echo "❌ IP-DiskANN cmake failed"; exit 1; }
261265
make -j${JOBS} || { echo "❌ IP-DiskANN build failed"; exit 1; }
262266
make install || echo " ⚠ IP-DiskANN install failed (not critical)"
263267
cd ../..
@@ -278,7 +282,7 @@ if [ -d "plsh" ]; then
278282
fi
279283
mkdir -p build
280284
cd build
281-
cmake .. || { echo "❌ PLSH cmake failed"; exit 1; }
285+
cmake -DCMAKE_INSTALL_PREFIX="$ALGORITHMS_IMPL_DIR/build/install" .. || { echo "❌ PLSH cmake failed"; exit 1; }
282286
make -j${JOBS} || { echo "❌ PLSH build failed"; exit 1; }
283287
make install || echo " ⚠ PLSH install failed (not critical)"
284288
cd ../..

0 commit comments

Comments
 (0)