Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
P
pybind11-test
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tammo Jan Dijkema
pybind11-test
Commits
02bc16f6
Commit
02bc16f6
authored
Apr 13, 2019
by
Tammo Jan Dijkema
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add examples
parent
ee0ded7b
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
143 additions
and
0 deletions
+143
-0
.gitignore
.gitignore
+2
-0
cython-example/CMakeLists.txt
cython-example/CMakeLists.txt
+11
-0
cython-example/apps/fib_cli.cpp
cython-example/apps/fib_cli.cpp
+12
-0
cython-example/fib_wrapper.pyx
cython-example/fib_wrapper.pyx
+5
-0
cython-example/include/fibonacci.h
cython-example/include/fibonacci.h
+4
-0
cython-example/setup.py
cython-example/setup.py
+22
-0
cython-example/src/fibonacci.cpp
cython-example/src/fibonacci.cpp
+14
-0
pybind11-example/Makefile
pybind11-example/Makefile
+35
-0
pybind11-example/apps/fib_cli.cpp
pybind11-example/apps/fib_cli.cpp
+12
-0
pybind11-example/fib_cli
pybind11-example/fib_cli
+0
-0
pybind11-example/include/fibonacci.h
pybind11-example/include/fibonacci.h
+4
-0
pybind11-example/src/fibonacci.cpp
pybind11-example/src/fibonacci.cpp
+14
-0
pybind11-example/src/fibonacci_wrapper.cpp
pybind11-example/src/fibonacci_wrapper.cpp
+8
-0
No files found.
.gitignore
View file @
02bc16f6
build/
*.so
*.dylib
cython-example/CMakeLists.txt
0 → 100644
View file @
02bc16f6
cmake_minimum_required
(
VERSION 3.1
)
project
(
Fibonacci VERSION 0.1
DESCRIPTION
"Calculate Fibonacci Numbers using C++"
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
)
cython-example/apps/fib_cli.cpp
0 → 100644
View file @
02bc16f6
#include <iostream>
#include "fibonacci.h"
int
main
()
{
for
(
unsigned
int
i
=
0
;
i
<
10
;
i
++
)
{
std
::
cout
<<
i
<<
": "
<<
fibonacci
(
i
)
<<
std
::
endl
;
}
return
0
;
}
cython-example/fib_wrapper.pyx
0 → 100644
View file @
02bc16f6
# cython: language_level = 3
# distutils: language = c++
cdef
extern
from
"fibonacci.h"
:
cpdef
unsigned
long
fibonacci
(
unsigned
int
n
)
cython-example/include/fibonacci.h
0 → 100644
View file @
02bc16f6
#ifndef FIBONACCI_H
#define FIBONACCI_H
unsigned
long
fibonacci
(
unsigned
int
n
);
#endif
cython-example/setup.py
0 → 100644
View file @
02bc16f6
from
setuptools
import
setup
,
Extension
from
Cython.Build
import
cythonize
import
os
ext_modules
=
[
Extension
(
'fib_wrapper'
,
sources
=
[
'fib_wrapper.pyx'
],
libraries
=
[
'fibonacci'
],
runtime_library_dirs
=
[
os
.
path
.
abspath
(
'build'
)],
extra_link_args
=
[
'-Wl,-rpath'
,
os
.
path
.
abspath
(
'build'
)],
include_dirs
=
[
'include'
],
library_dirs
=
[
'build'
],
)
]
setup
(
name
=
'fib_wrapper'
,
version
=
'0.0.1'
,
ext_modules
=
cythonize
(
ext_modules
)
)
cython-example/src/fibonacci.cpp
0 → 100644
View file @
02bc16f6
#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-example/Makefile
0 → 100644
View file @
02bc16f6
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-example/apps/fib_cli.cpp
0 → 100644
View file @
02bc16f6
#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-example/fib_cli
0 → 100755
View file @
02bc16f6
File added
pybind11-example/include/fibonacci.h
0 → 100644
View file @
02bc16f6
#ifndef FIBONACCI_H
#define FIBONACCI_H
unsigned
long
fibonacci
(
unsigned
int
n
);
#endif
pybind11-example/src/fibonacci.cpp
0 → 100644
View file @
02bc16f6
#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-example/src/fibonacci_wrapper.cpp
0 → 100644
View file @
02bc16f6
#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
Markdown
is supported
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