diff --git a/paddle/fluid/pybind/CMakeLists.txt b/paddle/fluid/pybind/CMakeLists.txt index 354f48c7bb940f0e912083c962eb4cc1c180b7c8..0a59caae2bbe815dc6f48fc40a3e451e2850a32a 100755 --- a/paddle/fluid/pybind/CMakeLists.txt +++ b/paddle/fluid/pybind/CMakeLists.txt @@ -572,25 +572,33 @@ if(WITH_PYTHON) list(APPEND PYBIND_DEPS custom_operator_node) endif() + # On Linux, cc_library(paddle SHARED ..) will generate the libpaddle.so, + # add a prefix `lib` by default, but on Windows, cc_library(paddle SHARED ..) + # will not add prefix, so it generate paddle.lib and paddle.pyd, + # we need to pay attention to the difference + set(SHARD_LIB_NAME paddle) + if(WIN32) + set(SHARD_LIB_NAME libpaddle) + endif() cc_library( - libpaddle SHARED + ${SHARD_LIB_NAME} SHARED SRCS ${PYBIND_SRCS} DEPS ${PYBIND_DEPS} ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS}) if(NOT ((NOT WITH_PYTHON) AND ON_INFER)) - add_dependencies(libpaddle legacy_eager_codegen) - add_dependencies(libpaddle eager_legacy_op_function_generator_cmd) + add_dependencies(${SHARD_LIB_NAME} legacy_eager_codegen) + add_dependencies(${SHARD_LIB_NAME} eager_legacy_op_function_generator_cmd) endif() if(NOT APPLE AND NOT WIN32) - target_link_libraries(libpaddle rt) + target_link_libraries(${SHARD_LIB_NAME} rt) endif() if(WITH_ROCM) - target_link_libraries(libpaddle ${ROCM_HIPRTC_LIB}) + target_link_libraries(${SHARD_LIB_NAME} ${ROCM_HIPRTC_LIB}) endif() get_property(os_dependency_modules GLOBAL PROPERTY OS_DEPENDENCY_MODULES) - target_link_libraries(libpaddle ${os_dependency_modules}) - add_dependencies(libpaddle op_function_generator_cmd) + target_link_libraries(${SHARD_LIB_NAME} ${os_dependency_modules}) + add_dependencies(${SHARD_LIB_NAME} op_function_generator_cmd) endif() diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index b935fb78f4e90bec1dfb9187d5f9628b12c872fc..b7d8eb1dcbc594c931a6a7e2b949aa0ff9bae54e 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -31,7 +31,6 @@ if(WIN32) # Python would use the .pyd by default under Windows series platform set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.pyd) set(FLUID_CORE_LIB ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.lib) - add_custom_command( OUTPUT ${FLUID_CORE} COMMAND cmake -E copy $ ${FLUID_CORE} @@ -41,8 +40,8 @@ else() set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.so) add_custom_command( OUTPUT ${FLUID_CORE} - COMMAND cmake -E copy $ ${FLUID_CORE} - DEPENDS libpaddle) + COMMAND cmake -E copy $ ${FLUID_CORE} + DEPENDS paddle) endif() set(FLUID_CORE_DEPS ${FLUID_CORE}) diff --git a/python/paddle/fluid/core.py b/python/paddle/fluid/core.py index 09a659ff5730a1fee198b65e5a67574b082f2f40..b58bead476a45ada73bc5d897cd8050885cbb224 100644 --- a/python/paddle/fluid/core.py +++ b/python/paddle/fluid/core.py @@ -20,14 +20,16 @@ import os import warnings import platform -core_suffix = 'so' +has_paddle_dy_lib = False + +dy_lib_name = 'libpaddle' +dy_lib_suffix = 'so' if os.name == 'nt': - core_suffix = 'pyd' + dy_lib_suffix = 'pyd' -has_libpaddle_so = False current_path = os.path.abspath(os.path.dirname(__file__)) -if os.path.exists(current_path + os.sep + 'libpaddle.' + core_suffix): - has_libpaddle_so = True +if os.path.exists(current_path + os.sep + dy_lib_name + '.' + dy_lib_suffix): + has_paddle_dy_lib = True try: if os.name == 'nt': @@ -193,8 +195,8 @@ def load_dso(dso_absolute_path): def pre_load(dso_name): - if has_libpaddle_so: - core_so = current_path + os.sep + 'libpaddle.' + core_suffix + if has_paddle_dy_lib: + core_so = current_path + os.sep + dy_lib_name + '.' + dy_lib_suffix else: core_so = None dso_path = get_dso_path(core_so, dso_name) @@ -290,10 +292,10 @@ try: from .libpaddle import _cleanup_mmap_fds from .libpaddle import _remove_tensor_list_mmap_fds except Exception as e: - if has_libpaddle_so: + if has_paddle_dy_lib: sys.stderr.write( 'Error: Can not import paddle core while this file exists: ' + - current_path + os.sep + 'libpaddle.' + core_suffix + '\n') + current_path + os.sep + 'libpaddle.' + dy_lib_suffix + '\n') if not avx_supported() and libpaddle.is_compiled_with_avx(): sys.stderr.write( "Error: Your machine doesn't support AVX, but the installed PaddlePaddle is avx core, "