0

I am trying to bridge my c++ code with python using pybind11. I have example.cpp file and it has an include to yices.h. yices.h is in usr/local/includes folder.

#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");
 }

When I try the test.py I am getting a segmentation error. How to link yices.h using pybind11?

from example import add

Here is the cmake file

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)
HasDW
  • 25
  • 1
  • 7

1 Answers1

1

You forgot to link it with gmp and yices:

target_link_libraries(example PUBLIC yices gmp)
Piotr Barejko
  • 608
  • 4
  • 15
  • This is working. Thank you very much. Can you please explain why I need to link it with gmp – HasDW Aug 25 '20 at 03:15
  • 1
    No worries! When I built your example I got an error during import time that module has undefined `gmp` symbols. That's why I linked with `gmp`. `yices` uses `gmp`. `gmp` is one of its prerequisites. – Piotr Barejko Aug 25 '20 at 04:09
  • Hi there is another issue. i have used an API iverilog. The path is not in "/usr/local/bin". How to link this? The path for the iverilog is something like this - /home/download/iverilog – HasDW Aug 25 '20 at 04:14
  • You can use `target_link_libraries(example PUBLIC full_path_to_library)` – Piotr Barejko Aug 25 '20 at 04:16
  • I tried that. But I am getting this error - /usr/bin/ld: /home/hasini/Downloads/iverilog/bin/iverilog: stdout: invalid version 4 (max 0) – HasDW Aug 25 '20 at 04:28
  • Are you sure you are linking with a library? To me `bin/iverilog` seems like an executable. Besides, I think you should look in here https://stackoverflow.com/questions/8774593/cmake-link-to-external-library – Piotr Barejko Aug 25 '20 at 04:37