如何解决Palisade 开发库无法编译示例代码
操作系统:Linux
几天以来,我一直试图从 Palisade FHE library 运行此示例代码。在成功编译库本身后,我尝试为其示例程序之一制作一个 makefile,并得到关于缺少命名空间的这个很长的错误。我是 C++ 的初学者,无法破译此错误消息。对于特别熟悉这个库的人来说,g++ 找不到 lbcrypto
。我搜索了整个系统,但没有找到具有此名称的文件。我不知道命名空间位于何处,也不知道如何将它包含在我的 makefile 中。这是我运行 make
时的 makefile 和错误。
生成文件
CC = g++
CFLAGS = -Wall -g
main: simple-integers.o ; $(CC) $(CFLAGS) -l /usr/local/include/palisade/pke/ciphertext.h -o main simple-integers.o
simple-integers.o: simple-integers.cpp ; $(CC) $(CFLAGS) -c simple-integers.cpp -I /usr/local/include/palisade/pke/ -I /usr/local/include/palisade/core -I /usr/local/include/palisade
错误
/usr/bin/ld: /home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:100: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorIlaptop% cat file.txt
g++ -Wall -g -o main simple-integers.o
/usr/bin/ld: simple-integers.o: warning: relocation against `_ZTVN8lbcrypto15IntegerEncodingE' in read-only section `.text._ZN8lbcrypto15IntegerEncodingC2ESt10shared_ptrINS_12ILDCRTParamsIN9bigintfxd10BigIntegerIjLj3500EEEEEES1_INS_18EncodingParamsImplEE[_ZN8lbcrypto15IntegerEncodingC5ESt10shared_ptrINS_12ILDCRTParamsIN9bigintfxd10BigIntegerIjLj3500EEEEEES1_INS_18EncodingParamsImplEE]'
/usr/bin/ld: /usr/bin/ld: DWARF error: could not find variable specification at offset 42f44
simple-integers.o: in function `main':
/home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:40: undefined reference to `lbcrypto::CryptoContextFactory<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > >::genCryptoContextBFVrns(unsigned long,lbcrypto::SecurityLevel,float,unsigned int,MODE,int,unsigned long,unsigned int)'
/usr/bin/ld: /home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:55: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > >::EvalMultKeyGen(std::shared_ptr<lbcrypto::LPPrivateKeyImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > > >)'
/usr/bin/ld: /home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:58: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > >::EvalAtIndexKeyGen(std::shared_ptr<lbcrypto::LPPrivateKeyImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > > >,std::vector<int,std::allocator<int> > const&,std::shared_ptr<lbcrypto::LPPublicKeyImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > > >)'
/usr/bin/ld: /home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:90: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > >::EvalAtIndex(std::shared_ptr<lbcrypto::CiphertextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > > const>,int) const'
/usr/bin/ld: /home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:91: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,int) const'
/usr/bin/ld: /home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:92: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,int) const'
/usr/bin/ld: /home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:93: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,int) const'
/usr/bin/ld: /home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:100: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > >::Decrypt(std::shared_ptr<lbcrypto::LPPrivateKeyImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::CiphertextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::PlaintextImpl>*)'
/usr/bin/ld: /home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:105: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::PlaintextImpl>*)'
/usr/bin/ld: /home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:109: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::PlaintextImpl>*)'
/usr/bin/ld: /home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:111: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::PlaintextImpl>*)'
/usr/bin/ld: /home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:113: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::PlaintextImpl>*)'
/usr/bin/ld: simple-integers.o:/home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:115: more undefined references to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::PlaintextImpl>*)' follow
/usr/bin/ld: simple-integers.o: in function `lbcrypto::PlaintextImpl::PlaintextImpl(std::shared_ptr<lbcrypto::ILDCRTParams<bigintfxd::BigInteger<unsigned int,3500u> > >,std::shared_ptr<lbcrypto::EncodingParamsImpl>,bool)':
/usr/local/include/palisade/core/encoding/plaintext.h:148: undefined reference to `lbcrypto::PolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > >::PolyImpl(std::shared_ptr<lbcrypto::ILDCRTParams<bigintfxd::BigInteger<unsigned int,Format,bool)'
/usr/bin/ld: /usr/local/include/palisade/core/encoding/plaintext.h:148: undefined reference to `lbcrypto::PolyImpl<bigintnat::NativeVector<bigintnat::NativeIntegerT<unsigned long> > >::PolyImpl()'
/usr/bin/ld: /usr/local/include/palisade/core/encoding/plaintext.h:148: undefined reference to `lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > >::DCRTPolyImpl(std::shared_ptr<lbcrypto::ILDCRTParams<bigintfxd::BigInteger<unsigned int,bool)'
/usr/bin/ld: /usr/local/include/palisade/core/encoding/plaintext.h:148: undefined reference to `lbcrypto::PolyImpl<bigintnat::NativeVector<bigintnat::NativeIntegerT<unsigned long> > >::~PolyImpl()'
/usr/bin/ld: /usr/local/include/palisade/core/encoding/plaintext.h:148: undefined reference to `lbcrypto::PolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > >::~PolyImpl()'
/usr/bin/ld: simple-integers.o: in function `lbcrypto::CKKSPackedEncoding::CKKSPackedEncoding(std::shared_ptr<lbcrypto::ILDCRTParams<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::EncodingParamsImpl>)':
/usr/local/include/palisade/core/encoding/ckkspackedencoding.h:67: undefined reference to `vtable for lbcrypto::CKKSPackedEncoding'
/usr/bin/ld: simple-integers.o: in function `lbcrypto::CoefPackedEncoding::CoefPackedEncoding(std::shared_ptr<lbcrypto::ILDCRTParams<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::EncodingParamsImpl>)':
/usr/local/include/palisade/core/encoding/coefpackedencoding.h:48: undefined reference to `vtable for lbcrypto::CoefPackedEncoding'
/usr/bin/ld: simple-integers.o: in function `lbcrypto::FractionalEncoding::FractionalEncoding(std::shared_ptr<lbcrypto::ILDCRTParams<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::EncodingParamsImpl>)':
/usr/local/include/palisade/core/encoding/fractionalencoding.h:67: undefined reference to `vtable for lbcrypto::FractionalEncoding'
/usr/bin/ld: simple-integers.o: in function `lbcrypto::IntegerEncoding::IntegerEncoding(std::shared_ptr<lbcrypto::ILDCRTParams<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::EncodingParamsImpl>)':
/usr/local/include/palisade/core/encoding/integerencoding.h:46: undefined reference to `vtable for lbcrypto::IntegerEncoding'
/usr/bin/ld: simple-integers.o: in function `lbcrypto::PackedEncoding::PackedEncoding(std::shared_ptr<lbcrypto::ILDCRTParams<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::EncodingParamsImpl>)':
/usr/bin/ld: simple-integers.o: in function `lbcrypto::ScalarEncoding::ScalarEncoding(std::shared_ptr<lbcrypto::ILDCRTParams<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::EncodingParamsImpl>)':
/usr/local/include/palisade/core/encoding/scalarencoding.h:46: undefined reference to `vtable for lbcrypto::ScalarEncoding'
/usr/bin/ld: simple-integers.o: in function `lbcrypto::StringEncoding::StringEncoding(std::shared_ptr<lbcrypto::ILDCRTParams<bigintfxd::BigInteger<unsigned int,std::shared_ptr<lbcrypto::EncodingParamsImpl>)':
/usr/bin/ld: simple-integers.o: in function `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > >::KeyGen()':
/usr/local/include/palisade/pke/cryptocontext.h:939: undefined reference to `lbcrypto::CryptoContextFactory<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > >::GetContextForPointer(lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > >*)'
/usr/bin/ld: simple-integers.o: in function `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > >::EvalMult(std::shared_ptr<lbcrypto::CiphertextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > > const>) const':
/usr/local/include/palisade/pke/cryptocontext.h:2522: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,3500u> > > >::GetEvalMultKeyVector(std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char> > const&)'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [Makefile:4: main] Error 1
/usr/bin/ld: /home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:100: undefined reference to `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorIlaptop% cat file.txt
g++ -Wall -g -o main simple-integers.o
/usr/bin/ld: simple-integers.o: warning: relocation against `_ZTVN8lbcrypto15IntegerEncodingE' in read-only section `.text._ZN8lbcrypto15IntegerEncodingC2ESt10shared_ptrINS_12ILDCRTParamsIN9bigintfxd10BigIntegerIjLj3500EEEEEES1_INS_18EncodingParamsImplEE[_ZN8lbcrypto15IntegerEncodingC5ESt10shared_ptrINS_12ILDCRTParamsIN9bigintfxd10BigIntegerIjLj3500EEEEEES1_INS_18EncodingParamsImplEE]'
/usr/bin/ld: /usr/bin/ld: DWARF error: could not find variable specification at offset 42f44
simple-integers.o: in function `main':
/home/admin/Libraries/palisade-release/src/pke/examples/simple-integers.cpp:40: undefined reference to `lbcrypto::CryptoContextFactory<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,bool)'
/usr/bin/ld: simple-integers.o: in function `lbcrypto::CryptoContextImpl<lbcrypto::DCRTPolyImpl<bigintfxd::BigVectorImpl<bigintfxd::BigInteger<unsigned int,std::allocator<char> > const&)'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [Makefile:4: main] Error 1
我尝试编译的示例代码
// @file simple-integers.cpp - Simple example for BFVrns (integer arithmetic).
// @author TPOC: contact@palisade-crypto.org
//
// @copyright Copyright (c) 2019,New Jersey Institute of Technology (NJIT))
// All rights reserved.
// Redistribution and use in source and binary forms,with or without
// modification,are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice,// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. THIS SOFTWARE IS
// PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES,INCLUDING,BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,// INDIRECT,INCIDENTAL,SPECIAL,EXEMPLARY,OR CONSEQUENTIAL DAMAGES
// (INCLUDING,PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE,DATA,OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT,STRICT LIABILITY,OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE,EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "palisade.h"
using namespace lbcrypto;
int main() {
// Sample Program: Step 1: Set CryptoContext
// Set the main parameters
int plaintextModulus = 65537;
double sigma = 3.2;
SecurityLevel securityLevel = HEStd_128_classic;
uint32_t depth = 2;
// Instantiate the crypto context
CryptoContext<DCRTPoly> cryptoContext =
CryptoContextFactory<DCRTPoly>::genCryptoContextBFVrns(
plaintextModulus,securityLevel,sigma,depth,OPTIMIZED);
// Enable features that you wish to use
cryptoContext->Enable(ENCRYPTION);
cryptoContext->Enable(SHE);
// Sample Program: Step 2: Key Generation
// Initialize Public Key Containers
LPKeyPair<DCRTPoly> keyPair;
// Generate a public/private key pair
keyPair = cryptoContext->KeyGen();
// Generate the relinearization key
cryptoContext->EvalMultKeyGen(keyPair.secretKey);
// Generate the rotation evaluation keys
cryptoContext->EvalAtIndexKeyGen(keyPair.secretKey,{1,2,-1,-2});
// Sample Program: Step 3: Encryption
// First plaintext vector is encoded
std::vector<int64_t> vectorOfInts1 = {1,3,4,5,6,7,8,9,10,11,12};
Plaintext plaintext1 = cryptoContext->MakePackedPlaintext(vectorOfInts1);
// Second plaintext vector is encoded
std::vector<int64_t> vectorOfInts2 = {3,1,12};
Plaintext plaintext2 = cryptoContext->MakePackedPlaintext(vectorOfInts2);
// Third plaintext vector is encoded
std::vector<int64_t> vectorOfInts3 = {1,12};
Plaintext plaintext3 = cryptoContext->MakePackedPlaintext(vectorOfInts3);
// The encoded vectors are encrypted
auto ciphertext1 = cryptoContext->Encrypt(keyPair.publicKey,plaintext1);
auto ciphertext2 = cryptoContext->Encrypt(keyPair.publicKey,plaintext2);
auto ciphertext3 = cryptoContext->Encrypt(keyPair.publicKey,plaintext3);
// Sample Program: Step 4: Evaluation
// Homomorphic additions
auto ciphertextAdd12 = cryptoContext->EvalAdd(ciphertext1,ciphertext2);
auto ciphertextAddResult =
cryptoContext->EvalAdd(ciphertextAdd12,ciphertext3);
// Homomorphic multiplications
auto ciphertextMul12 = cryptoContext->EvalMult(ciphertext1,ciphertext2);
auto ciphertextMultResult =
cryptoContext->EvalMult(ciphertextMul12,ciphertext3);
// Homomorphic rotations
auto ciphertextRot1 = cryptoContext->EvalAtIndex(ciphertext1,1);
auto ciphertextRot2 = cryptoContext->EvalAtIndex(ciphertext1,2);
auto ciphertextRot3 = cryptoContext->EvalAtIndex(ciphertext1,-1);
auto ciphertextRot4 = cryptoContext->EvalAtIndex(ciphertext1,-2);
// Sample Program: Step 5: Decryption
// Decrypt the result of additions
Plaintext plaintextAddResult;
cryptoContext->Decrypt(keyPair.secretKey,ciphertextAddResult,&plaintextAddResult);
// Decrypt the result of multiplications
Plaintext plaintextMultResult;
cryptoContext->Decrypt(keyPair.secretKey,ciphertextMultResult,&plaintextMultResult);
// Decrypt the result of rotations
Plaintext plaintextRot1;
cryptoContext->Decrypt(keyPair.secretKey,ciphertextRot1,&plaintextRot1);
Plaintext plaintextRot2;
cryptoContext->Decrypt(keyPair.secretKey,ciphertextRot2,&plaintextRot2);
Plaintext plaintextRot3;
cryptoContext->Decrypt(keyPair.secretKey,ciphertextRot3,&plaintextRot3);
Plaintext plaintextRot4;
cryptoContext->Decrypt(keyPair.secretKey,ciphertextRot4,&plaintextRot4);
plaintextRot1->SetLength(vectorOfInts1.size());
plaintextRot2->SetLength(vectorOfInts1.size());
plaintextRot3->SetLength(vectorOfInts1.size());
plaintextRot4->SetLength(vectorOfInts1.size());
std::cout << "Plaintext #1: " << plaintext1 << std::endl;
std::cout << "Plaintext #2: " << plaintext2 << std::endl;
std::cout << "Plaintext #3: " << plaintext3 << std::endl;
// Output results
std::cout << "\nResults of homomorphic computations" << std::endl;
std::cout << "#1 + #2 + #3: " << plaintextAddResult << std::endl;
std::cout << "#1 * #2 * #3: " << plaintextMultResult << std::endl;
std::cout << "Left rotation of #1 by 1: " << plaintextRot1 << std::endl;
std::cout << "Left rotation of #1 by 2: " << plaintextRot2 << std::endl;
std::cout << "Right rotation of #1 by 1: " << plaintextRot3 << std::endl;
std::cout << "Right rotation of #1 by 2: " << plaintextRot4 << std::endl;
return 0;
}
为简洁起见,省略了一些错误。
解决方法
我想问一个澄清问题。为什么您尝试手动编写 const { Client } = require('discord.js');
const bot = new Client();
const TOKEN = process.env.TOKEN;
const PREFIX = '!';
bot.on('ready',() => {
console.log('This bot is active!');
});
bot.on('message',(message) => {
if (message.content === '!dm') {
const taggedUser = message.mentions.users.first();
const user = client.users.cache.get(taggedUser.username);
user.send('test');
}
});
bot.login(TOKEN);
文件,而不是使用基于 Makefile
的 PALISADE 推荐方法?说明位于 https://gitlab.com/palisade/palisade-development/-/wikis/Instructions-for-building-user-projects-that-use-PALISADE。您应该只需复制 cmake
用户示例并进行细微更改即可编译。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。