Skip to content

Commit

Permalink
Add an example of how to link to libsnark.so
Browse files Browse the repository at this point in the history
Issue #18
  • Loading branch information
benma committed Aug 10, 2016
1 parent 46eeb6a commit 4b506a3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ with some (currently sparse) comments, install the `doxygen` and `graphviz` pack

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.

See a full example in ./link_example.

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

Expand Down
10 changes: 10 additions & 0 deletions link_example/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Set this to the directory where you installed libsnark.
# If you install to linker_example (`make install PREFIX=linker_example`),
# the default prefix will work.
INSTALL_PREFIX=.

all:
$(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

run:
LD_LIBRARY_PATH=$(INSTALL_PREFIX)/lib ./main
11 changes: 11 additions & 0 deletions link_example/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>

#include <gadgetlib2/examples/simple_example.hpp>
#include <zk_proof_systems/ppzksnark/r1cs_ppzksnark/examples/run_r1cs_ppzksnark.hpp>

int main() {
const libsnark::r1cs_example<libsnark::Fr<libsnark::default_ec_pp> > example = libsnark::gen_r1cs_example_from_gadgetlib2_protoboard(100);
const bool test_serialization = true;
const bool bit = libsnark::run_r1cs_ppzksnark<libsnark::default_ec_pp>(example, test_serialization);
std::cout << (bit ? "Success" : "Failure") << std::endl;
}

0 comments on commit 4b506a3

Please sign in to comment.