pybind / cmake_example

Example pybind11 module built with a CMake-based build system
Other
626 stars 221 forks source link

Process finished with exit code -1073741515 #23

Open vpaladino778 opened 5 years ago

vpaladino778 commented 5 years ago

I'm receiving this error while tying to put together a simple pybind cmake example app.

Process finished with exit code -1073741515 (0xC0000135)

I've been google for hours now trying to figure out the source of this error. When i comment out the lines utilizing pybind (First 3 lines in main). It compiles and runs correctly and reaches the print statement. I'm pretty new to CMake so it's possible i set it up wrong. I added the lines pointing to python because I was receiving errors about missing python dll's. I'm using CLion and MSVS 2017 if that makes any difference.

example.cpp

#include <iostream>
#include <../pybind11/include/pybind11/pybind11.h>
#include <../pybind11/include/pybind11/embed.h>
#include <CImg.h>

namespace py = pybind11;
using namespace py::literals;

int main(int argc, char *argv[])
{
    py::scoped_interpreter guard{};

    auto example = py::module::import("example");
    auto resultobj = example.attr("add")(2,2);
    int result = resultobj.cast<int>();
    std::cout << result;
}

example.py

def add(a,b):
    return a+b

Cmakelists.txt:

cmake_minimum_required(VERSION 3.14)
project(TestApp)

set(CMAKE_CXX_STANDARD 11)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})

link_directories(C:\\Users\\myuser\\AppData\\Local\\Programs\\Python\\Python37-32\\libs)

add_subdirectory(lib/pybind11)
include_directories(lib/CImg-2.6.7)

add_executable(example src/example.cpp)
target_link_libraries(example PRIVATE pybind11::embed)

File Structure

TestApp ----src/ --------example.cpp ----lib/ --------Cimg-2.6.7/ --------pybind/