HarryR / ethsnarks

A toolkit for viable zk-SNARKS on Ethereum, Web, Mobile and Desktop
GNU Lesser General Public License v3.0
240 stars 57 forks source link

MacOS compiling errors #126

Closed mathcrypto closed 5 years ago

mathcrypto commented 5 years ago

When I use ethsnarks as submodule in my project and try to compile I get this error:


CMake Error at depends/ethsnarks/depends/CMakeLists.txt:11 (add_executable):
 Cannot find source file:

    /Users/amirabouguera/SSLES/depends/SHA3IUF/sha3test.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx

CMake Error at depends/ethsnarks/depends/CMakeLists.txt:8 (add_executable):
  Cannot find source file:

    /Users/amirabouguera/SSLES/depends/SHA3IUF/sha3sum.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx

CMake Error at depends/ethsnarks/depends/CMakeLists.txt:4 (add_library):
  Cannot find source file:

    /Users/amirabouguera/SSLES/depends/SHA3IUF/sha3.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx

CMake Error at depends/ethsnarks/depends/CMakeLists.txt:11 (add_executable):
  No SOURCES given to target: sha3test

CMake Error at depends/ethsnarks/depends/CMakeLists.txt:8 (add_executable):
  No SOURCES given to target: sha3sum

CMake Error at depends/ethsnarks/depends/CMakeLists.txt:4 (add_library):
  No SOURCES given to target: SHA3IUF

-- Build files have been written to: /Users/amirabouguera/SSLES/build
make: *** [cmake_check_build_system] Error 1  ```
HarryR commented 5 years ago

Hi

I can reproduce this error if I do the following:

git clone git@github.com:HarryR/ethsnarks.git
cd ethsnarks
cmake .

However, if I do:

git clone git@github.com:HarryR/ethsnarks.git
cd ethsnarks
make

This fixes the problem.

Note: the Makefile creates a directory build, and does a self-contained CMake build within that directory, you will run into errors if you just do cmake ..

The problem is git submodules aren't pulled, so the dependant source code doesn't exist, the Makefile handles the build process, along with NPM dependencies etc.

mathcrypto commented 5 years ago

So when I follow your instructions, I get this error after the command make (it does not find gmp.h)

git submodule update --init --recursive
mkdir -p build
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C build
[  1%] Building CXX object CMakeFiles/ff.dir/depends/libsnark/depends/libff/libff/algebra/curves/alt_bn128/alt_bn128_g1.cpp.o
In file included from /Users/amirabouguera/SSLES/depends/ethsnarks/depends/libsnark/depends/libff/libff/algebra/curves/alt_bn128/alt_bn128_g1.cpp:8:
In file included from /Users/amirabouguera/SSLES/depends/ethsnarks/depends/libsnark/depends/libff/libff/algebra/curves/alt_bn128/alt_bn128_g1.hpp:12:
In file included from /Users/amirabouguera/SSLES/depends/ethsnarks/depends/libsnark/depends/libff/libff/algebra/curves/alt_bn128/alt_bn128_init.hpp:11:
In file included from /Users/amirabouguera/SSLES/depends/ethsnarks/depends/libsnark/depends/libff/libff/algebra/fields/fp.hpp:13:
In file included from /Users/amirabouguera/SSLES/depends/ethsnarks/depends/libsnark/depends/libff/libff/algebra/exponentiation/exponentiation.hpp:17:
/Users/amirabouguera/SSLES/depends/ethsnarks/depends/libsnark/depends/libff/libff/algebra/fields/bigint.hpp:15:10: fatal error: 
      'gmp.h' file not found
#include <gmp.h>
         ^~~~~~~
1 error generated.
make[3]: *** [CMakeFiles/ff.dir/depends/libsnark/depends/libff/libff/algebra/curves/alt_bn128/alt_bn128_g1.cpp.o] Error 1
make[2]: *** [CMakeFiles/ff.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [build/src/verify] Error 2

I even added ${GMP_INCLUDE_DIR} in ethsnarks/CMakeLists.txt as you recommended here https://github.com/HarryR/ethsnarks-miximus/issues/12 and still get same error.

HarryR commented 5 years ago

Ah ok, apologies for the inconvenience.

Do your changes match this: https://github.com/HarryR/ethsnarks/pull/123/commits/cbe7970975d05acfcac3b08781668abb3c72d790#diff-af3b638bc2a3e6c650974192a53c729190 where ${GMP_INCLUDE_DIR} is added to both the PUBLIC and INTERFACE lines for target_include_directories(ff ...

I forgot to include those change in CMakeLists.txt to close-off that bug.

The build works on:

If you have both of the lines changed (in the above commit which will be merged into master asap), and it still doesn't work, then I need to get to the root of the problem.

I am investigating removing GMP as a dependency, because it is also difficult to build for iOS.

mathcrypto commented 5 years ago

Thank you for the quick response @HarryR, yes I have changed both lines to match this https://github.com/HarryR/ethsnarks/commit/cbe7970975d05acfcac3b08781668abb3c72d790#diff-af3b638bc2a3e6c650974192a53c729190 and still having same issue because of gmp error.

By the way, I have MacOS Mojave 10.14.1

HarryR commented 5 years ago

I have added OSX 10.14.4 (with xcode 10.2) to the Travis CI matrix, it builds and passes the tests. This branch includes the changes to CMakeLists.txt

See: https://travis-ci.org/HarryR/ethsnarks/jobs/545966195

I'm not sure why it's not building on your computer, as I can't replicate it, and you've done the workaround that somebody else said that worked. *shrug*

I will have a go at reproducing the build error, as it's frustrating that people can't build it on newer OSX versions even though the Travis CI builds work on latest OSX.

HarryR commented 5 years ago

There are two reasons I can think of:

1) gmp isn't installed (either via Brew, or otherwise), meaning GMP_INCLUDE_DIR in CMakeCache.txt would be invalid or empty. 2) CMake isn't finding GMP, and it isn't raising an error when it can't find it

However, when I uninstall gmp via Brew, then CMake (v3.14.5) errors before building because it can't find the library. After re-installing gmp via Brew, then the build is successful.

mathcrypto commented 5 years ago

Thank you @HarryR , I have deleted the build folder and started again and it works now.

   rm -r build/
   git clone git@github.com:HarryR/ethsnarks.git
   cd ethsnarks
   make 
HarryR commented 5 years ago

Awesome :D