Skip to content

Commit 6ba2b17

Browse files
committed
Update README Example instructions
1 parent 10ab97d commit 6ba2b17

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

README.md

+20-25
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
2-
ALPHA: BEING TESTED
3-
4-
Cpp2Py is the Python-C++ interfacing tool of the TRIQS project, provided here as a standalone project. (The TRIQS website is under http://ipht.cea.fr/triqs. Start there to learn about TRIQS.)
1+
Cpp2Py is the Python-C++ interfacing tool of the [TRIQS](https://triqs.github.io) project, provided here as a standalone project.
52

63
Installation
7-
====================
4+
============
85

96
To install Cpp2Py, follow the installation steps:
107

@@ -15,50 +12,48 @@ cmake -DCMAKE_INSTALL_PREFIX=INSTALL_DIR ../cpp2py
1512
make && make install
1613
```
1714

18-
This installs the library in `INSTALL_DIR`. You should now update your PYTHONPATH to make it available to the python interpreter:
15+
This installs the library in `INSTALL_DIR`.
16+
In order to make Cpp2Py available in your current environment you should run
1917

2018
```bash
21-
export PYTHONPATH=INSTALL_DIR/lib/python3.4/site-packages:$PYTHONPATH
19+
source INSTALL_DIR/share/cpp2pyvars.sh
2220
```
2321

2422

25-
2623
Example
27-
================
24+
=======
2825

29-
Suppose you have created a c++ source file `mymodule.hpp` in a folder `SRC`:
26+
Make sure that you have loaded Cpp2Py into your environment as instructed above.
27+
Created a C++ source file `mymodule.hpp` in a folder `SRC`:
3028

3129
```c++
3230
///A wonderful little class
3331
class myclass{
34-
int a,b;
32+
int a, b;
3533

36-
public:
37-
myclass(int a_, int b_):a(a_),b(b_){}
34+
public:
35+
myclass(int a_, int b_) : a(a_), b(b_) {}
3836

39-
///getter for member a
40-
int get_a() const { return a;}
37+
///getter for member a
38+
int get_a() const { return a;}
4139
};
4240
```
4341

4442
In the same folder, create a file `CMakeLists.txt`:
4543

4644
```cmake
47-
cmake_minimum_required(VERSION 3.5)
45+
cmake_minimum_required(VERSION 3.0.2)
4846
find_package(Cpp2Py REQUIRED)
4947
50-
set(CPP2PY_ADD_MODULE_ADDITIONAL_PYTHONPATH "INSTALL_DIR/lib/python3.4/site-packages/")
51-
52-
include_directories(${Cpp2Py_DIR}/../../include)
53-
include_directories(.)
54-
5548
add_cpp2py_module(mymodule)
49+
target_compile_options(mymodule PRIVATE -std=c++17)
50+
target_include_directories(mymodule PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
5651
```
5752

5853
Then, in the `SRC` folder, issue the command
5954

6055
```
61-
INSTALL_DIR/bin/c++2py mymodule.hpp
56+
c++2py mymodule.hpp
6257
```
6358

6459
This creates a file `mymodule_desc.py`.
@@ -67,16 +62,16 @@ Exit the `SRC` folder and create a `BUILD` folder. Then, issue the following com
6762

6863
```bash
6964
cd BUILD
70-
cmake -DCMAKE_PREFIX_PATH=INSTALL_DIR/lib/cmake/cpp2py ../SRC
71-
make
65+
cmake ../SRC
66+
make
7267
```
7368

7469
In the `BUILD` dir, you should see a `mymodule.so` file. You can now use your c++ class in Python:
7570

7671
```python
7772
import mymodule
7873
A = mymodule.Myclass(4,5)
79-
A.get_a() #outputs 4
74+
print(A.get_a())
8075
```
8176

8277
By convention, c++ classes of the type `my_little_class` are converted in python classes of the type `MyLittleClass`.

0 commit comments

Comments
 (0)