首页 > 解决方案 > pybind11 & dlib:gcc 命令的 CMake 替代方案

问题描述

我正在尝试*.whl使用 pybind11 和 dlib 从 C++ 源代码构建一个 python 包。

这个 GCC 对我很有用:

gcc -O3 -Wall -shared -I /home/user/dlib /home/user/dlib/dlib/all/source.cpp -lpthread -lX11 -ljpeg -lpng -DDLIB_JPEG_SUPPORT -DDLIB_PNG_SUPPORT -std=c++11 -fPIC `python3 -m pybind11 --includes` age_and_gender.cpp -o age_and_gender`python3-config --extension-suffix`

现在我正在尝试*.whl从这个示例构建 python 包: https ://github.com/pybind/cmake_example

我的CMakeLists.txt文件:

cmake_minimum_required(VERSION 2.8.12)

if (CMAKE_VERSION VERSION_LESS 3.0)
  PROJECT(example_app CXX)
else()
  cmake_policy(SET CMP0048 NEW)
  PROJECT(example_app VERSION "1.0.0" LANGUAGES CXX)
endif()

add_compile_options(
    -O3
    -Wall
    -shared
    -fPIC
    -lpthread
    -lX11
    -ljpeg
    -lpng
    -DDLIB_JPEG_SUPPORT
    -DDLIB_PNG_SUPPORT
    -std=c++11
)

add_executable(dlib_source "/home/user/dlib/dlib/all/source.cpp")
include_directories("/home/user/dlib")

add_subdirectory(pybind11)
pybind11_add_module(example_app "src/main.cpp")

我认为这不是正确的版本CMakeLists.txt鉴于我的“gcc”命令有效,帮助编写正确的 CMakeLists.txt 文件。

当我尝试打包时,出现此错误import*.whl

from example_app import *
Segmentation fault (core dumped)

标签: c++gcccmakedlibpybind11

解决方案


推荐阅读