在之前介绍的HElib使用介绍中,当时学的很迷糊,对make ,cmake,makelists等不是很明白,因为之前并不是很了解Linux,自己这两天在B站上学了点相关知识,如何运行Helib中的example_prpgram文件夹下hello_example.cpp呢?
特别强调 一定要看:
https://github.com/homenc/HElib/blob/master/INSTALL.md
下面是我自己琢磨出来的:仅供参考…
make
编译,生成可执行文件。而cmakelists又解放了makelists的编写,只需要cmake .
然后make
编译即可。详细请自己学习,这只是我的一点感觉。。。。
看到CMakeLists.txt,那就要cmake .
,不过最好先mkdir build,cd build
-- The CXX compiler identification is GNU 7.5.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/local/share/cmake/helib/helibTargets.cmake:80 (message):
The imported target "helib" references the file
"/usr/local/lib/libhelib.a"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/local/share/cmake/helib/helibTargets.cmake"
but not all the files it references.
Call Stack (most recent call first):
/usr/local/share/cmake/helib/helibConfig.cmake:30 (include)
CMakeLists.txt:13 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/wbq/HElib/example_program/build/CMakeFiles/CMakeOutput.log".
See also "/home/wbq/HElib/example_program/build/CMakeFiles/CMakeError.log".
原因是:CMakeLists.txt:13 (find_package)
解决:回到HElib 编译:
- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found GMP: /usr/local/lib/libgmp.so (found suitable version "6.2.0", minimum required is "6.0.0")
-- Found NTL: /usr/local/lib/libntl.a (found suitable version "11.4.3", minimum required is "11.0.0")
-- Looking for NTL_THREADS
-- Looking for NTL_THREADS - found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wbq/HElib/build
:~/HElib/build$ ls
CMakeCache.txt cmake_install.cmake lib src
CMakeFiles get_gmp_version Makefile
make 编译:
:~/HElib/build$ make
Scanning dependencies of target helib
[ 2%] Building CXX object src/CMakeFiles/helib.dir/ArgMap.cpp.o
[ 4%] Building CXX object src/CMakeFiles/helib.dir/BenesNetwork.cpp.o
[ 7%] Building CXX object src/CMakeFiles/helib.dir/binaryArith.cpp.o
[ 9%] Building CXX object src/CMakeFiles/helib.dir/binaryCompare.cpp.o
[ 11%] Building CXX object src/CMakeFiles/helib.dir/binio.cpp.o
[ 14%] Building CXX object src/CMakeFiles/helib.dir/bluestein.cpp.o
[ 16%] Building CXX object src/CMakeFiles/helib.dir/CModulus.cpp.o
[ 19%] Building CXX object src/CMakeFiles/helib.dir/Ctxt.cpp.o
[ 21%] Building CXX object src/CMakeFiles/helib.dir/debugging.cpp.o
[ 23%] Building CXX object src/CMakeFiles/helib.dir/DoubleCRT.cpp.o
[ 26%] Building CXX object src/CMakeFiles/helib.dir/EaCx.cpp.o
[ 28%] Building CXX object src/CMakeFiles/helib.dir/EncryptedArray.cpp.o
[ 30%] Building CXX object src/CMakeFiles/helib.dir/eqtesting.cpp.o
[ 33%] Building CXX object src/CMakeFiles/helib.dir/EvalMap.cpp.o
[ 35%] Building CXX object src/CMakeFiles/helib.dir/extractDigits.cpp.o
[ 38%] Building CXX object src/CMakeFiles/helib.dir/fft.cpp.o
[ 40%] Building CXX object src/CMakeFiles/helib.dir/FHEContext.cpp.o
[ 42%] Building CXX object src/CMakeFiles/helib.dir/FHE.cpp.o
[ 45%] Building CXX object src/CMakeFiles/helib.dir/hypercube.cpp.o
[ 47%] Building CXX object src/CMakeFiles/helib.dir/IndexSet.cpp.o
[ 50%] Building CXX object src/CMakeFiles/helib.dir/intraSlot.cpp.o
[ 52%] Building CXX object src/CMakeFiles/helib.dir/KeySwitching.cpp.o
[ 54%] Building CXX object src/CMakeFiles/helib.dir/matching.cpp.o
[ 57%] Building CXX object src/CMakeFiles/helib.dir/matmul.cpp.o
[ 59%] Building CXX object src/CMakeFiles/helib.dir/norms.cpp.o
[ 61%] Building CXX object src/CMakeFiles/helib.dir/NumbTh.cpp.o
[ 64%] Building CXX object src/CMakeFiles/helib.dir/OptimizePermutations.cpp.o
[ 66%] Building CXX object src/CMakeFiles/helib.dir/PAlgebra.cpp.o
[ 69%] Building CXX object src/CMakeFiles/helib.dir/PermNetwork.cpp.o
[ 71%] Building CXX object src/CMakeFiles/helib.dir/permutations.cpp.o
[ 73%] Building CXX object src/CMakeFiles/helib.dir/polyEval.cpp.o
[ 76%] Building CXX object src/CMakeFiles/helib.dir/powerful.cpp.o
[ 78%] Building CXX object src/CMakeFiles/helib.dir/primeChain.cpp.o
[ 80%] Building CXX object src/CMakeFiles/helib.dir/recryption.cpp.o
[ 83%] Building CXX object src/CMakeFiles/helib.dir/replicate.cpp.o
[ 85%] Building CXX object src/CMakeFiles/helib.dir/sample.cpp.o
[ 88%] Building CXX object src/CMakeFiles/helib.dir/tableLookup.cpp.o
[ 90%] Building CXX object src/CMakeFiles/helib.dir/timing.cpp.o
[ 92%] Building CXX object src/CMakeFiles/helib.dir/zzX.cpp.o
[ 95%] Building CXX object src/CMakeFiles/helib.dir/PGFFT.cpp.o
[ 97%] Building CXX object src/CMakeFiles/helib.dir/fhe_stats.cpp.o
[100%] Linking CXX static library ../lib/libhelib.a
[100%] Built target helib
安装:
sudo make install
[sudo] wbq 鐨勫瘑鐮侊細
[100%] Built target helib
Install the project...
-- Install configuration: "Debug"
-- Installing: /usr/local/lib/libhelib.a
-- Installing: /usr/local/include/helib/ArgMap.h
-- Installing: /usr/local/include/helib/binaryArith.h
-- Installing: /usr/local/include/helib/binaryCompare.h
-- Installing: /usr/local/include/helib/binio.h
-- Installing: /usr/local/include/helib/bluestein.h
-- Installing: /usr/local/include/helib/clonedPtr.h
-- Installing: /usr/local/include/helib/CModulus.h
-- Installing: /usr/local/include/helib/CtPtrs.h
-- Installing: /usr/local/include/helib/Ctxt.h
-- Installing: /usr/local/include/helib/debugging.h
-- Installing: /usr/local/include/helib/DoubleCRT.h
-- Installing: /usr/local/include/helib/EncryptedArray.h
-- Installing: /usr/local/include/helib/EvalMap.h
-- Installing: /usr/local/include/helib/FHEContext.h
-- Installing: /usr/local/include/helib/FHE.h
-- Installing: /usr/local/include/helib/hypercube.h
-- Installing: /usr/local/include/helib/IndexMap.h
-- Installing: /usr/local/include/helib/IndexSet.h
-- Installing: /usr/local/include/helib/intraSlot.h
-- Installing: /usr/local/include/helib/matching.h
-- Installing: /usr/local/include/helib/matmul.h
-- Installing: /usr/local/include/helib/multicore.h
-- Installing: /usr/local/include/helib/norms.h
-- Installing: /usr/local/include/helib/NumbTh.h
-- Installing: /usr/local/include/helib/PAlgebra.h
-- Installing: /usr/local/include/helib/permutations.h
-- Installing: /usr/local/include/helib/polyEval.h
-- Installing: /usr/local/include/helib/powerful.h
-- Installing: /usr/local/include/helib/primeChain.h
-- Installing: /usr/local/include/helib/PtrMatrix.h
-- Installing: /usr/local/include/helib/PtrVector.h
-- Installing: /usr/local/include/helib/randomMatrices.h
-- Installing: /usr/local/include/helib/range.h
-- Installing: /usr/local/include/helib/recryption.h
-- Installing: /usr/local/include/helib/replicate.h
-- Installing: /usr/local/include/helib/sample.h
-- Installing: /usr/local/include/helib/tableLookup.h
-- Installing: /usr/local/include/helib/timing.h
-- Installing: /usr/local/include/helib/zzX.h
-- Installing: /usr/local/include/helib/assertions.h
-- Installing: /usr/local/include/helib/exceptions.h
-- Installing: /usr/local/include/helib/PGFFT.h
-- Installing: /usr/local/include/helib/fhe_stats.h
-- Old export file "/usr/local/share/cmake/helib/helibTargets.cmake" will be replaced. Removing files [/usr/local/share/cmake/helib/helibTargets-noconfig.cmake].
-- Installing: /usr/local/share/cmake/helib/helibTargets.cmake
-- Installing: /usr/local/share/cmake/helib/helibTargets-debug.cmake
-- Installing: /usr/local/share/cmake/helib/helibConfig.cmake
-- Installing: /usr/local/share/cmake/helib/helibConfigVersion.cmake
:~/HElib/build$ ls
CMakeCache.txt cmake_install.cmake install_manifest.txt Makefile
CMakeFiles get_gmp_version lib src
回到example
:~/HElib/example_program/build$ cmake ..
-- The CXX compiler identification is GNU 7.5.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wbq/HElib/example_program/build
查看编译:
wbq@wbq-virtual-machine:~/HElib/example_program/build$ ls
CMakeCache.txt CMakeFiles cmake_install.cmake Makefile
wbq@wbq-virtual-machine:~/HElib/example_program/build$ make
结果:
Scanning dependencies of target helib_example
[ 50%] Building CXX object CMakeFiles/helib_example.dir/helib_example.cpp.o
[100%] Linking CXX executable helib_example
[100%] Built target helib_example
wbq@wbq-virtual-machine:~/HElib/example_program/build$ ls
CMakeCache.txt cmake_install.cmake Makefile
CMakeFiles helib_example
## 运行:
wbq@wbq-virtual-machine:~/HElib/example_program/build$ ./helib_example
Initialising context object...
Building modulus chain...
m = 32109, p = 4999, phi(m) = 16560
ord(p)=690
generator 320 has order (== Z_m^*) of 6
generator 3893 has order (== Z_m^*) of 2
generator 14596 has order (== Z_m^*) of 2
T = [1 14596 3893 21407 320 14915 25618 11023 6073 20668 9965 27479 16820 31415 10009 27523 20197 2683 24089 9494 9131 23726 2320 19834 ]
Security: 127.626
Creating secret key...
Generating key-switching matrices...
Number of slots: 24
Initial Ptxt: [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23]
Decrypted Ptxt: [0 2 8 18 32 50 72 98 128 162 200 242 288 338 392 450 512 578 648 722 800 882 968 1058]