toppers / hakoniwa-core-cpp-client

5 stars 3 forks source link

Python binding でSIGSEGVが発生した場合の対応方法 #58

Open tmori opened 2 months ago

tmori commented 2 months ago

対応方法

CMakeLists.txtでPythonのバージョンと利用するPythonバージョンが一致しないとSIGSEGVで落ちますので、以下のように対応できます。

cmake_minimum_required(VERSION 3.12)

project(hakoniwa_python_project
    LANGUAGES C CXX
)

# PythonのバージョンがCMakeで指定されているかどうかを確認
if(${CMAKE_VERSION} LESS 3.12)
    find_package(PythonLibs REQUIRED)
    include_directories(${PYTHON_INCLUDE_DIRS})
    set(HAKO_PYTHON_LIBS ${PYTHON_LIBRARIES})
else()
    set(Python3_EXECUTABLE "$ENV{HOME}/.pyenv/versions/3.10.0/bin/python3.10")
    set(Python3_INCLUDE_DIRS "$ENV{HOME}/.pyenv/versions/3.10.0/include/python3.10")
    set(Python3_LIBRARIES "$ENV{HOME}/.pyenv/versions/3.10.0/lib/libpython3.10.dylib")
    find_package(Python3 3.10 EXACT REQUIRED)

    include_directories(${Python3_INCLUDE_DIRS})
    set(HAKO_PYTHON_LIBS ${Python3_LIBRARIES})

    # Debugging messages
    message(STATUS "Python3_VERSION: ${Python3_VERSION}")
    message(STATUS "Python3_INCLUDE_DIRS: ${Python3_INCLUDE_DIRS}")
endif()

message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
message(STATUS "PYTHON_INCLUDE_DIRS: ${PYTHON_INCLUDE_DIRS}")
message(STATUS "Python_INCLUDE_DIRS: ${Python_INCLUDE_DIRS}")
message(STATUS "PYTHON_LIBRARIES: ${PYTHON_LIBRARIES}")
message(STATUS "Python_LIBRARIES: ${Python_LIBRARIES}")
message(STATUS "Python_LIBRARY_DIRS: ${Python_LIBRARY_DIRS}")

add_library(
    hako_asset_python SHARED
    hako_asset_python.cpp
)

target_link_libraries(
    hako_asset_python 
    assets
    ${HAKO_PYTHON_LIBS}
)
tmori commented 2 months ago

condaは実績ありません。

SIGSEGVで落ちます。

tmori commented 2 months ago

Windowsはpyenvがないと思われるので、面倒ですね。

tmori commented 2 months ago

CMAKE_VERSIONは、3.12以降にしたい。