Skip to content

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

@tmori

Description

@tmori

対応方法

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}
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions