Commit 95509f60 authored by Jørgen Lien Sellæg's avatar Jørgen Lien Sellæg
Browse files

move to use same name on cpp file

parent 6217ee3c
......@@ -8,13 +8,17 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -Wall -Wextra")
add_subdirectory("lib/pybind11")
find_package(Python3 COMPONENTS Development)
add_library(c-api c-api/main.cpp)
add_library(c-api SHARED c-api/module.cpp)
set_target_properties(
c-api
PROPERTIES
PREFIX ""
OUTPUT_NAME Maths.cpython-37m-x86_64-linux-gnu
)
target_include_directories(c-api PUBLIC ${Python3_INCLUDE_DIRS})
target_link_libraries(c-api ${Python3_LIBRARIES})
pybind11_add_module("Prime" pybind/heavy_example/module.cpp)
pybind11_add_module("Maths" pybind/sum_example/module.cpp)
pybind11_add_module("CppMath" pybind/sum_example/module.cpp)
#define PY_SSIZE_T_CLEAN
#include <Python.h>
int sum_ints(int a, int b) {
return a + b;
}
static PyObject *bind_sum(PyObject *, PyObject *args) {
int a, b;
if (!PyArg_ParseTuple(args, "ii", &a, &b))
return NULL;
return PyLong_FromLong(sum_ints(a, b));
}
static PyObject *SumError;
static PyMethodDef math_methods[] = {
{ "sum", bind_sum, METH_VARARGS, "Sum two ints" }
};
static struct PyModuleDef math_module = {
PyModuleDef_HEAD_INIT,
"Maths",
nullptr,
-1,
math_methods,
nullptr,
nullptr,
nullptr,
nullptr
};
PyMODINIT_FUNC PyInit_Maths(void) {
PyObject *m = nullptr;
m = PyModule_Create2(&math_module, 1013);
if (!m) {
return nullptr;
}
SumError = PyErr_NewException("sum.error", nullptr, nullptr);
Py_IncRef(SumError);
PyModule_AddObject(m, "error", SumError);
return m;
}
from distutils.core import setup, Extension
module1 = Extension('Maths',
sources = ['main.cpp'])
sources = ['module.cpp'])
setup (name = 'Maths',
version = '1.0',
......
......@@ -11,4 +11,4 @@ from Maths import sum
result = sum(3, 2)
print(result)
print("\n" + str(result) + "\n")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment