Skip to content

fix: macos dynamic link libpaddle#2

Open
gouzil wants to merge 2 commits intoPFCCLab:paddlefrom
gouzil:fix/macos_build
Open

fix: macos dynamic link libpaddle#2
gouzil wants to merge 2 commits intoPFCCLab:paddlefrom
gouzil:fix/macos_build

Conversation

@gouzil
Copy link
Copy Markdown

@gouzil gouzil commented Feb 24, 2026

fix

  • 修复 macos 下动态链接库获取失败,调整为根据不同系统加载不同的动态链接库
  • 修复 macos 运行时加载 ffmpeg 动态库失败
  • 增加 cmake 阶段检查

Copilot AI review requested due to automatic review settings February 24, 2026 06:37
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes macOS compatibility issues with Paddle library linking by adding platform-specific dynamic library resolution logic. The changes add build-time validation to ensure required Paddle libraries exist before attempting to link them.

Changes:

  • Introduced resolve_paddle_library() function to validate library paths at CMake configuration time
  • Added platform-specific library path detection for macOS, Windows, and Linux
  • Restricted Linux-specific --as-needed linker flag to prevent macOS linker errors

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +35 to +38
set(PADDLE_LIBPHI_CORE_CANDIDATES
"${PADDLE_PATH}/libs/libphi_core.dll"
"${PADDLE_PATH}/libs/phi_core.dll"
)
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, the library candidates should list .lib files before .dll files. Import libraries (.lib) are typically used for linking, while dynamic libraries (.dll) are loaded at runtime. If both files exist, the current order will select the .dll first, which may not work correctly with CMake's target_link_libraries. Consider reordering to check for .lib files first.

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +43
if(APPLE)
# Paddle on macOS ships libpaddle as .so, while runtime deps are .dylib.
set(PADDLE_LIBPADDLE_CANDIDATES "${PADDLE_PATH}/base/libpaddle.so")
set(PADDLE_LIBCOMMON_CANDIDATES "${PADDLE_PATH}/libs/libcommon.dylib")
set(PADDLE_LIBPHI_CORE_CANDIDATES "${PADDLE_PATH}/libs/libphi_core.dylib")
elseif(WIN32)
set(PADDLE_LIBPADDLE_CANDIDATES
"${PADDLE_PATH}/base/libpaddle.dll"
"${PADDLE_PATH}/base/libpaddle.lib"
)
set(PADDLE_LIBCOMMON_CANDIDATES
"${PADDLE_PATH}/libs/libcommon.dll"
"${PADDLE_PATH}/libs/common.dll"
)
set(PADDLE_LIBPHI_CORE_CANDIDATES
"${PADDLE_PATH}/libs/libphi_core.dll"
"${PADDLE_PATH}/libs/phi_core.dll"
)
else()
set(PADDLE_LIBPADDLE_CANDIDATES "${PADDLE_PATH}/base/libpaddle.so")
set(PADDLE_LIBCOMMON_CANDIDATES "${PADDLE_PATH}/libs/libcommon.so")
set(PADDLE_LIBPHI_CORE_CANDIDATES "${PADDLE_PATH}/libs/libphi_core.so")
endif()
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code should validate that PADDLE_PATH is defined and non-empty before using it to construct library paths. If PADDLE_PATH is not set, the error message from resolve_paddle_library will be confusing (e.g., "Unable to locate Paddle library for PADDLE_LIBPADDLE. Tried: /base/libpaddle.so"). Consider adding a check like if(NOT DEFINED PADDLE_PATH OR PADDLE_PATH STREQUAL "") with a clear error message before this platform-specific code block.

Copilot uses AI. Check for mistakes.
return()
endif()
endforeach()
message(FATAL_ERROR "Unable to locate Paddle library for ${out_var}. Tried: ${ARGN}")
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message could be more user-friendly. Currently it says "Unable to locate Paddle library for PADDLE_LIBPADDLE" which uses the variable name. Consider changing the message to be more descriptive, for example: "Unable to locate Paddle library '${out_var}'. Searched in: ${ARGN}" or maintain a mapping from variable names to descriptive names like "libpaddle", "libcommon", etc.

Suggested change
message(FATAL_ERROR "Unable to locate Paddle library for ${out_var}. Tried: ${ARGN}")
message(FATAL_ERROR "Unable to locate Paddle library '${out_var}'. Searched in: ${ARGN}")

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +29
"${PADDLE_PATH}/base/libpaddle.dll"
"${PADDLE_PATH}/base/libpaddle.lib"
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, the library candidates should list .lib files before .dll files. Import libraries (.lib) are typically used for linking, while dynamic libraries (.dll) are loaded at runtime. If both files exist, the current order will select the .dll first, which may not work correctly with CMake's target_link_libraries. Consider reordering to check for .lib files first.

Suggested change
"${PADDLE_PATH}/base/libpaddle.dll"
"${PADDLE_PATH}/base/libpaddle.lib"
"${PADDLE_PATH}/base/libpaddle.lib"
"${PADDLE_PATH}/base/libpaddle.dll"

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +34
set(PADDLE_LIBCOMMON_CANDIDATES
"${PADDLE_PATH}/libs/libcommon.dll"
"${PADDLE_PATH}/libs/common.dll"
)
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, the library candidates should list .lib files before .dll files. Import libraries (.lib) are typically used for linking, while dynamic libraries (.dll) are loaded at runtime. If both files exist, the current order will select the .dll first, which may not work correctly with CMake's target_link_libraries. Consider reordering to check for .lib files first.

Copilot uses AI. Check for mistakes.
@gouzil
Copy link
Copy Markdown
Author

gouzil commented Feb 25, 2026

@ShigureNyako 帮我看看这么改动态链接有没有什么问题

Copy link
Copy Markdown

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们目标是减少 diff,这样是不是 diff 太大了?

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.

3 participants