HElib搭建问题

HElib搭建问题

一、搭建

在虚拟器中搭建HElib我就不赘述了,可以依照官网教程和博客搭建。我当时也是依照博客一步步搭建HElib环境,把环境都搭建好了,最后一步运行样例程序的时候,出现了运行错误,发现博客下面好多人也出现同样的坑。

二、问题

前面环境都搭建好了,接下来运行样例程序的时候遇到的问题。

运行的BGV_packed_arithmetic样例程序时候,遇到如下问题:

wbw@wbw-virtual-machine:~/Desktop/HElib-master/examples/BGV_packed_arithmetic$ make
[ 50%] Building CXX object CMakeFiles/BGV_packed_arithmetic.dir/BGV_packed_arithmetic.cpp.o
In file included from /usr/local/include/helib/IndexSet.h:21:0,
                 from /usr/local/include/helib/IndexMap.h:20,
                 from /usr/local/include/helib/DoubleCRT.h:34,
                 from /usr/local/include/helib/helib.h:22,
                 from /home/wbw/Desktop/HElib-master/examples/BGV_packed_arithmetic/BGV_packed_arithmetic.cpp:20:
/usr/local/include/helib/JsonWrapper.h:11:35: error: ‘any’ in namespace ‘std’ does not name a type
   explicit JsonWrapper(const std::any& json_repr) : json_obj(json_repr) {}
                                   ^~~
/usr/local/include/helib/JsonWrapper.h:13:14: error: ‘any’ in namespace ‘std’ does not name a type
   const std::any& getJSONobj() const { return json_obj; }
              ^~~
/usr/local/include/helib/JsonWrapper.h:23:8: error: ‘any’ in namespace ‘std’ does not name a type
   std::any json_obj;
        ^~~
/usr/local/include/helib/JsonWrapper.h: In constructor ‘helib::JsonWrapper::JsonWrapper(const int&)’:
/usr/local/include/helib/JsonWrapper.h:11:53: error: class ‘helib::JsonWrapper’ does not have any field named ‘json_obj’
   explicit JsonWrapper(const std::any& json_repr) : json_obj(json_repr) {}
                                                     ^~~~~~~~
/usr/local/include/helib/JsonWrapper.h: In member function ‘helib::JsonWrapper::operator bool() const’:
/usr/local/include/helib/JsonWrapper.h:12:43: error: ‘json_obj’ was not declared in this scope
   explicit operator bool() const { return json_obj.has_value(); }
                                           ^~~~~~~~
In file included from /usr/local/include/helib/Context.h:27:0,
                 from /usr/local/include/helib/helib.h:23,
                 from /home/wbw/Desktop/HElib-master/examples/BGV_packed_arithmetic/BGV_packed_arithmetic.cpp:20:
/usr/local/include/helib/scheme.h: At global scope:
/usr/local/include/helib/scheme.h:39:25: error: ‘string_view’ in namespace ‘std’ does not name a type
   static constexpr std::string_view schemeName = "CKKS";
                         ^~~~~~~~~~~
/usr/local/include/helib/scheme.h:56:25: error: ‘string_view’ in namespace ‘std’ does not name a type
   static constexpr std::string_view schemeName = "BGV";
                         ^~~~~~~~~~~
In file included from /usr/local/include/helib/helib.h:23:0,
                 from /home/wbw/Desktop/HElib-master/examples/BGV_packed_arithmetic/BGV_packed_arithmetic.cpp:20:
/usr/local/include/helib/Context.h:212:22: error: ‘optional’ in namespace ‘std’ does not name a template type
           const std::optional<ModChainParams>& mparams,
                      ^~~~~~~~
/usr/local/include/helib/Context.h:212:30: error: expected ‘,’ or ‘...’ before ‘<’ token
           const std::optional<ModChainParams>& mparams,
                              ^
/usr/local/include/helib/Context.h:244:25: error: ‘string_view’ in namespace ‘std’ does not name a type
   static constexpr std::string_view typeName = "Context";
                         ^~~~~~~~~~~
/usr/local/include/helib/Context.h:1057:24: error: ‘optional’ is not a member of ‘std’
   const std::pair<std::optional<Context::ModChainParams>,
                        ^~~~~~~~
/usr/local/include/helib/Context.h:1057:24: note: suggested alternative: ‘internal’
   const std::pair<std::optional<Context::ModChainParams>,
                        ^~~~~~~~
                        internal
/usr/local/include/helib/Context.h:1057:24: error: ‘optional’ is not a member of ‘std’
/usr/local/include/helib/Context.h:1057:24: note: suggested alternative: ‘internal’
   const std::pair<std::optional<Context::ModChainParams>,
                        ^~~~~~~~
                        internal
/usr/local/include/helib/Context.h:1057:56: error: wrong number of template arguments (1, should be 2)
   const std::pair<std::optional<Context::ModChainParams>,
                                                        ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from /home/wbw/Desktop/HElib-master/examples/BGV_packed_arithmetic/BGV_packed_arithmetic.cpp:18:
/usr/include/c++/7/bits/stl_pair.h:208:12: note: provided for ‘template<class _T1, class _T2> struct std::pair’
     struct pair
            ^~~~
In file included from /usr/local/include/helib/helib.h:23:0,
                 from /home/wbw/Desktop/HElib-master/examples/BGV_packed_arithmetic/BGV_packed_arithmetic.cpp:20:
/usr/local/include/helib/Context.h:1057:57: error: expected unqualified-id before ‘,’ token
   const std::pair<std::optional<Context::ModChainParams>,
                                                         ^
/usr/local/include/helib/Context.h:1094:25: error: ‘string_view’ in namespace ‘std’ does not name a type
   static constexpr std::string_view typeName = "ContextBuilder";
                         ^~~~~~~~~~~
In file included from /usr/local/include/helib/helib.h:24:0,
                 from /home/wbw/Desktop/HElib-master/examples/BGV_packed_arithmetic/BGV_packed_arithmetic.cpp:20:
/usr/local/include/helib/Ctxt.h:510:25: error: ‘string_view’ in namespace ‘std’ does not name a type
   static constexpr std::string_view typeName = "Ctxt";
                         ^~~~~~~~~~~
In file included from /usr/local/include/helib/helib.h:25:0,
                 from /home/wbw/Desktop/HElib-master/examples/BGV_packed_arithmetic/BGV_packed_arithmetic.cpp:20:
/usr/local/include/helib/keySwitching.h:93:25: error: ‘string_view’ in namespace ‘std’ does not name a type
   static constexpr std::string_view typeName = "KeySwitch";
                         ^~~~~~~~~~~
In file included from /usr/local/include/helib/helib.h:26:0,
                 from /home/wbw/Desktop/HElib-master/examples/BGV_packed_arithmetic/BGV_packed_arithmetic.cpp:20:
/usr/local/include/helib/keys.h:77:25: error: ‘string_view’ in namespace ‘std’ does not name a type
   static constexpr std::string_view typeName = "PubKey";
                         ^~~~~~~~~~~
/usr/local/include/helib/keys.h:322:25: error: ‘string_view’ in namespace ‘std’ does not name a type
   static constexpr std::string_view typeName = "SecKey";
                         ^~~~~~~~~~~
In file included from /usr/local/include/helib/helib.h:27:0,
                 from /home/wbw/Desktop/HElib-master/examples/BGV_packed_arithmetic/BGV_packed_arithmetic.cpp:20:
/usr/local/include/helib/EncryptedArray.h:2173:25: error: ‘string_view’ in namespace ‘std’ does not name a type
   static constexpr std::string_view typeName = "PtxtArray";
                         ^~~~~~~~~~~
In file included from /usr/local/include/helib/helib.h:28:0,
                 from /home/wbw/Desktop/HElib-master/examples/BGV_packed_arithmetic/BGV_packed_arithmetic.cpp:20:
/usr/local/include/helib/Ptxt.h:199:25: error: ‘string_view’ in namespace ‘std’ does not name a type
   static constexpr std::string_view typeName = "Ptxt";
                         ^~~~~~~~~~~
/home/wbw/Desktop/HElib-master/examples/BGV_packed_arithmetic/BGV_packed_arithmetic.cpp: In function ‘int main(int, char**)’:
/home/wbw/Desktop/HElib-master/examples/BGV_packed_arithmetic/BGV_packed_arithmetic.cpp:59:39: error: use of deleted function ‘helib::Context::Context(helib::Context&&)’
                                .build();
                                       ^
In file included from /usr/local/include/helib/helib.h:23:0,
                 from /home/wbw/Desktop/HElib-master/examples/BGV_packed_arithmetic/BGV_packed_arithmetic.cpp:20:
/usr/local/include/helib/Context.h:671:3: note: declared here
   Context(Context&& other) = delete;
   ^~~~~~~
CMakeFiles/BGV_packed_arithmetic.dir/build.make:62: recipe for target 'CMakeFiles/BGV_packed_arithmetic.dir/BGV_packed_arithmetic.cpp.o' failed
make[2]: *** [CMakeFiles/BGV_packed_arithmetic.dir/BGV_packed_arithmetic.cpp.o] Error 1
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/BGV_packed_arithmetic.dir/all' failed
make[1]: *** [CMakeFiles/BGV_packed_arithmetic.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

其中std::any这些都是源码里面的出现。

三、解决

查阅了一下相关的错误,发现是由于样例程序是使用C++17新特性带来的问题,而本地的Cmake使用的是默认版本C++11,因此需要在你的运行 CMakeLists.txt添加下列语句

wbw@wbw-virtual-machine:~/Desktop/HElib-master/examples/BGV_packed_arithmetic$ ls
BGV_packed_arithmetic      CMakeCache.txt  cmake_install.cmake  helib.log
BGV_packed_arithmetic.cpp  CMakeFiles      CMakeLists.txt       Makefile
wbw@wbw-virtual-machine:~/Desktop/HElib-master/examples/BGV_packed_arithmetic$ vim CMakeCache.txt

添加内容

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(helib)

add_executable(BGV_packed_arithmetic BGV_packed_arithmetic.cpp)

target_link_libraries(BGV_packed_arithmetic helib)

运行成功截图
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值