Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
pybind11-test
Commits
2c1f9e8d
Commit
2c1f9e8d
authored
Apr 13, 2019
by
Tammo Jan Dijkema
Browse files
Add CMake-pybind11 (without pybind11 for now)
parent
02bc16f6
Changes
7
Hide whitespace changes
Inline
Side-by-side
pybind11-cmake/CMakeLists.txt
0 → 100644
View file @
2c1f9e8d
cmake_minimum_required
(
VERSION 3.1
)
project
(
Fibonacci VERSION 0.1
DESCRIPTION
"Calculate Fibonacci numbers using C++, with python binding"
LANGUAGES CXX
)
add_library
(
fibonacci SHARED src/fibonacci.cpp include/fibonacci.h
)
target_include_directories
(
fibonacci PUBLIC include
)
add_executable
(
fib_cli apps/fib_cli.cpp
)
target_link_libraries
(
fib_cli PUBLIC fibonacci
)
pybind11-cmake/Makefile
0 → 100644
View file @
2c1f9e8d
all
:
libfibonacci.so fibmod fib_cli
fib_cli
:
apps/fib_cli.cpp libfibonacci.so
# compile fib_cli.cpp using the c++ compiler
# save to `fib_cli`
# link against the library `fibonacci`
# include the current directory in the directories searched for libraries
# include the current directory in the directories searched for headers
# compile the path where the library is to find into the binary
$(CXX)
apps/fib_cli.cpp
\
-o
fib_cli
\
-lfibonacci
\
-L
.
\
-Iinclude
\
-Wl
,-rpath .
libfibonacci.so
:
include/fibonacci.h src/fibonacci.cpp
# compile fibonacci.cpp into a shared library
# into libfibonacci.so
$(CXX)
src/fibonacci.cpp
\
-I
include
\
-o
libfibonacci.so
\
-Wl
,-rpath
.
\
--shared
fibmod
:
libfibonacci.so src/fibonacci_wrapper.cpp
# compile a python wrapper using pybind 11
$(CXX)
-O3
-Wall
-shared
-std
=
c++11
-undefined
dynamic_lookup
\
-Iinclude
-L
.
-lfibonacci
\
`
python3
-m
pybind11
--includes
`
\
src/fibonacci_wrapper.cpp
\
-o
fibmod
`
python3-config
--extension-suffix
`
clean
:
rm
-f
fib_cli libfibonacci.so fibmod.cpython
*
fib_cli
pybind11-cmake/apps/fib_cli.cpp
0 → 100644
View file @
2c1f9e8d
#include
<iostream>
#include
"fibonacci.h"
int
main
()
{
for
(
unsigned
int
i
=
0
;
i
<
10
;
i
++
)
{
std
::
cout
<<
i
<<
": "
<<
fibonacci
(
i
)
<<
std
::
endl
;
}
return
0
;
}
pybind11-cmake/fib_cli
0 → 100755
View file @
2c1f9e8d
File added
pybind11-cmake/include/fibonacci.h
0 → 100644
View file @
2c1f9e8d
#ifndef FIBONACCI_H
#define FIBONACCI_H
unsigned
long
fibonacci
(
unsigned
int
n
);
#endif
pybind11-cmake/src/fibonacci.cpp
0 → 100644
View file @
2c1f9e8d
#include
"fibonacci.h"
unsigned
long
fibonacci
(
unsigned
int
n
)
{
unsigned
long
n0
=
1
;
unsigned
long
n1
=
1
;
unsigned
long
tmp
=
1
;
for
(
unsigned
int
i
=
0
;
i
<
n
;
i
++
)
{
tmp
=
n1
;
n1
=
n0
+
n1
;
n0
=
tmp
;
}
return
n0
;
}
pybind11-cmake/src/fibonacci_wrapper.cpp
0 → 100644
View file @
2c1f9e8d
#include
<pybind11/pybind11.h>
#include
"fibonacci.h"
PYBIND11_MODULE
(
fibmod
,
m
)
{
m
.
doc
()
=
"pybind11 example plugin for fibonacci"
;
m
.
def
(
"fibonacci"
,
&
fibonacci
,
"Fibonacci function using C++"
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment