2025-07-14 15:43:55 +02:00
..
2025-07-03 07:45:51 +02:00
2025-07-14 15:43:55 +02:00

🛠️ Building

🐧 Linux (Fedora)

  1. Generate the C++ code
    circom --c --r1cs --no_asm pol.circom
    
  2. Compile
    make pol
    

🪟 Windows (Cross-compile from Linux)

  1. Generate the C++ code
    circom --c --r1cs --no_asm pol.circom
    
  2. Enter working directory
    cd pol_cpp
    
  3. Replace the Makefile The autogenerated Makefile does not support cross-compilation. Replace the Makefile contents 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
    ```
  1. Compile
    make pol.exe
    
  2. Bundle
    1. Copy .dlls
      MINGW_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} .
      
    2. Copy .dat
      cp pol.dat pol.exe.dat
      
    3. Bundle
      tar -czf pol-x86_64.tar.gz pol.exe pol.exe.dat *.dll