尝试桥接usr / local / include中的yices库时,Pybind11中出现分段错误

问题描述

我正在尝试使用pybind11将我的c ++代码与python桥接。我有example.cpp文件,并且它包含到yices.h。 yices.h位于usr / local / includes文件夹中。

#include <pybind11/pybind11.h>
#include "yices.h"   

int add(int i,int j) {
    yices_init();
    return i + j;
}

namespace py = pybind11;

PYBIND11_MODULE(example,m) {
    // optional module docstring
    m.doc() = "pybind11 example plugin";

    // define add function
    m.def("add",&add,"A function which adds two numbers");
 }

当我尝试test.py时,出现了细分错误。如何使用pybind11链接yices.h?

from example import add

这是cmake文件

cmake_minimum_required(VERSION 2.8.12)
project(example)

find_package(PythonLibs)
include_directories(${PYTHON_INCLUDE_Dirs})

add_subdirectory(pybind11)
pybind11_add_module(example example.cpp)

解决方法

您忘记将其与gmpyices链接:

target_link_libraries(example PUBLIC yices gmp)