• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

bin/H03-May-2022-206137

c++/cpp2py/H03-Sep-2020-2,5111,430

cmake/H03-May-2022-421349

cpp2cxx/H03-May-2022-18590

cpp2py/H03-May-2022-3,7732,710

cpp2rst/H03-May-2022-1,375793

test/H03-Sep-2020-9938

.clang-formatH A D03-Sep-20201.3 KiB4644

.gitignoreH A D03-Sep-20201.9 KiB157126

CITATIONS.bibH A D03-Sep-2020923 2623

ChangeLog.mdH A D03-Sep-2020681 2515

JenkinsfileH A D03-Sep-202086 43

README.mdH A D03-Sep-20201.8 KiB8760

cmake_uninstall.cmake.inH A D03-Sep-20201,003 2220

cpp2py.modulefile.inH A D03-Sep-20201.1 KiB3527

cpp2pyvars.sh.inH A D03-Sep-2020363 86

README.md

1Cpp2Py is the Python-C++ interfacing tool of the [TRIQS](https://triqs.github.io) project, provided here as a standalone project.
2
3Installation
4============
5
6To install Cpp2Py, follow the installation steps:
7
8```bash
9git clone  https://github.com/TRIQS/cpp2py.git cpp2py
10mkdir build && cd build
11cmake -DCMAKE_INSTALL_PREFIX=INSTALL_DIR ../cpp2py
12make && make install
13```
14
15This installs the library in `INSTALL_DIR`.
16In order to make Cpp2Py available in your current environment you should run
17
18```bash
19source INSTALL_DIR/share/cpp2pyvars.sh
20```
21
22
23Example
24=======
25
26Make sure that you have loaded Cpp2Py into your environment as instructed above.
27Created a C++ source file `mymodule.hpp` in a folder `SRC`:
28
29```c++
30///A wonderful little class
31class myclass{
32  int a, b;
33
34  public:
35    myclass(int a_, int b_) : a(a_), b(b_) {}
36
37    ///getter for member a
38    int get_a() const { return a;}
39};
40```
41
42In the same folder, create a file `CMakeLists.txt`:
43
44```cmake
45cmake_minimum_required(VERSION 3.0.2)
46find_package(Cpp2Py REQUIRED)
47
48add_cpp2py_module(mymodule)
49target_compile_options(mymodule PRIVATE -std=c++17)
50target_include_directories(mymodule PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
51```
52
53Then, in the `SRC` folder, issue the command
54
55```
56c++2py mymodule.hpp
57```
58
59This creates a file `mymodule_desc.py`.
60
61Exit the `SRC` folder and create a `BUILD` folder. Then, issue the following commands:
62
63```bash
64cd BUILD
65cmake ../SRC
66make
67```
68
69In the `BUILD` dir, you should see a `mymodule.so` file. You can now use your c++ class in Python:
70
71```python
72import mymodule
73A = mymodule.Myclass(4,5)
74print(A.get_a())
75```
76
77By convention, c++ classes of the type `my_little_class` are converted in python classes of the type `MyLittleClass`.
78
79License
80===============
81
82Before you proceed, make sure you have read the `LICENSE.txt` file.
83
84Enjoy!
85
86The TRIQS team
87