Skip to content

Commit 6be0121

Browse files
committed
Add an example of how to link to libsnark.so
Issue #18
1 parent 46eeb6a commit 6be0121

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ with some (currently sparse) comments, install the `doxygen` and `graphviz` pack
262262

263263
To develop an application that uses libsnark, you could add it within the libsnark directory tree and adjust the Makefile, but it is far better to build libsnark as a (shared or static) library. You can then write your code in a separate directory tree, and link it against libsnark.
264264

265+
See a full example in ./link_example/.
265266

266267
To build just the shared object library `libsnark.so`, run:
267268

link_example/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Set this to the directory where you installed libsnark.
2+
# If you install to link_example (`make install PREFIX=link_example`),
3+
# the default prefix will work.
4+
INSTALL_PREFIX=.
5+
6+
all:
7+
$(CXX) main.cpp -o main -std=c++11 -L$(INSTALL_PREFIX)/lib -lsnark -lsupercop -lgmp -lgmpxx -I$(INSTALL_PREFIX)/include -I$(INSTALL_PREFIX)/include/libsnark -DCURVE_BN128
8+
9+
run:
10+
LD_LIBRARY_PATH=$(INSTALL_PREFIX)/lib ./main

link_example/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <iostream>
2+
3+
#include <gadgetlib2/examples/simple_example.hpp>
4+
#include <zk_proof_systems/ppzksnark/r1cs_ppzksnark/examples/run_r1cs_ppzksnark.hpp>
5+
6+
int main() {
7+
const libsnark::r1cs_example<libsnark::Fr<libsnark::default_ec_pp> > example = libsnark::gen_r1cs_example_from_gadgetlib2_protoboard(100);
8+
const bool test_serialization = true;
9+
const bool bit = libsnark::run_r1cs_ppzksnark<libsnark::default_ec_pp>(example, test_serialization);
10+
std::cout << (bit ? "Success" : "Failure") << std::endl;
11+
}

0 commit comments

Comments
 (0)