🛠️ Building
🐧 Linux (Fedora)
- Generate the C++ code
circom --c --r1cs --no_asm pol.circom - Compile
make pol
🪟 Windows (Cross-compile from Linux)
- Generate the C++ code
circom --c --r1cs --no_asm pol.circom - Enter working directory
cd pol_cpp - Replace the Makefile
The autogenerated
Makefiledoes not support cross-compilation. Replace theMakefilecontents with the following:
========== General ==========
DEPS_HPP = circom.hpp calcwit.hpp fr.hpp
========== Native Linux build ==========
CXX = g++ CXXFLAGS = -std=c++11 -O3 -I. LDFLAGS = -lgmp
OBJS = main.o calcwit.o fr.o pol.o
all: pol
%.o: %.cpp $(DEPS_HPP) $(CXX) -Wno-address-of-packed-member -c $< $(CXXFLAGS)
pol: $(OBJS) $(CXX) -o $@ $^ $(LDFLAGS)
========== Windows cross-compilation ==========
CXX_WIN = x86_64-w64-mingw32-g++ CC_WIN = x86_64-w64-mingw32-gcc CXXFLAGS_WIN = -std=c++11 -O3 -I. -Iinclude -Duint="unsigned int" LDFLAGS_WIN = -Llib -lgmp -lmman
WIN_OBJS = main.win.o calcwit.win.o fr.win.o pol.win.o mman.win.o
%.win.o: %.cpp $(DEPS_HPP) $(CXX_WIN) -Wno-address-of-packed-member -c $< -o $@ $(CXXFLAGS_WIN)
mman.win.o: deps/mman-win32/mman.c $(CC_WIN) -c $< -o $@
pol.exe: $(WIN_OBJS) $(CXX_WIN) -o $@ $^ $(LDFLAGS_WIN)
========== Cleanup ==========
clean:
$(RM) *.o *.win.o pol pol.exe
4. Install Dependencies 1. Cross-Compilerbash
sudo dnf install mingw64-gcc mingw64-gcc-c++ # Compiler
2. Directory structurebash
mkdir -p include/sys
mkdir -p deps
mkdir -p lib
```mkdir -p include/sys
mkdir -p deps
mkdir -p lib
3. `sys/mman.h`
```bash
git clone https://github.com/alitrack/mman-win32.git deps/mman-win32
# cp deps/mman-win32/mman.h ./sys/
####
cd deps/mman-win32
./configure
make CC=x86_64-w64-mingw32-gcc
cd ../..
cp deps/mman-win32/mman.h include/sys/
cp deps/mman-win32/libmman.a lib
```
4. `nlohmann/json`
```bash
mkdir -p include/nlohmann
wget https://raw.githubusercontent.com/nlohmann/json/develop/single_include/nlohmann/json.hpp -O include/nlohmann/json.hpp
```
5. `gmp`
```
sudo dnf install mingw64-gmp
```
- Compile
make pol.exe - Bundle
- Copy
.dllsMINGW_DLL_DIR="$(x86_64-w64-mingw32-gcc -print-sysroot)/mingw/bin" cp "$MINGW_DLL_DIR"/{libgcc_s_seh-1.dll,libgmp-10.dll,libwinpthread-1.dll,libstdc++-6.dll} . - Copy
.datcp pol.dat pol.exe.dat - Bundle
tar -czf pol-x86_64.tar.gz pol.exe pol.exe.dat *.dll
- Copy