Как связать библиотеки с помощью em++/emcc?

Я написал функцию C++ для выполнения криптографии RSA с использованием библиотек crypto++. Я пытаюсь преобразовать его в функции, которые я могу вызывать в Javascript с помощью emsdk. Я просмотрел документ и не увидел простого способа сделать это. Мой исходный файл С++:

      #include <string>
using std::string;

#include <iostream>
using std::cout;
using std::cerr;
using std::endl;

#include "cryptopp/cryptlib.h"
#include "cryptopp/rsa.h"
#include "cryptopp/files.h"
#include "cryptopp/osrng.h"

#include "emscripten/bind.h"

using CryptoPP::RSA;
using CryptoPP::InvertibleRSAFunction;
using CryptoPP::RSAES_OAEP_SHA_Encryptor;
using CryptoPP::RSAES_OAEP_SHA_Decryptor;
using CryptoPP::StringSink;
using CryptoPP::StringSource;
using CryptoPP::PK_EncryptorFilter;
using CryptoPP::PK_DecryptorFilter;
using CryptoPP::FileSink;
using CryptoPP::FileSource;
using CryptoPP::AutoSeededRandomPool;
using CryptoPP::DecodingResult;
using CryptoPP::SHA1;

using namespace CryptoPP;
using namespace emscripten;

string generateKeys() {
    AutoSeededRandomPool rng;

    InvertibleRSAFunction parameters;
    parameters.GenerateRandomWithKeySize(rng, 1024);

    RSA::PrivateKey privateKey(parameters);
    RSA::PublicKey publicKey(parameters);
    string pubKey;
    publicKey.Save(StringSink(pubKey).Ref());
    privateKey.Save(FileSink("privkey.der", true).Ref());
    return pubKey;
}

string encrypt(string pubKey, string plain) {
    AutoSeededRandomPool rng;
    string cipher;
    RSA::PublicKey publicKey;
    publicKey.Load(StringSource(pubKey, true, NULL).Ref());
    RSAES_OAEP_SHA_Encryptor e(publicKey);
    StringSource(plain, true,
        new PK_EncryptorFilter(rng, e,
            new StringSink(cipher)
        ) // PK_EncryptorFilter
    ); // StringSource
    return cipher;
}

string decrypt(const char* filename, string cipher) {
    AutoSeededRandomPool rng;
    RSA::PrivateKey privateKey;
    string recovered;
    privateKey.Load(FileSource(filename, true).Ref());

    RSAES_OAEP_SHA_Decryptor d(privateKey);

    StringSource(cipher, true,
        new PK_DecryptorFilter(rng, d,
            new StringSink(recovered)
        ) // PK_EncryptorFilter
    ); // StringSource
    return recovered;
}

int main(int argc, char* argv[]) {
        string pubKey = generateKeys();
        string cipher = encrypt(pubKey, "Hello world");
        string recovered = decrypt("privkey.der", cipher);
        cout << pubKey << endl << cipher << endl << recovered << endl;

    return 0;
}

Я пробовал некоторые команды, которые, как я думал, помогут

      em++ Source.cpp -o source.html -sEXPORTED_FUNCTIONS=_generateKeys,_encrypt,_decrypt -sEXPORTED_RUNTIME_METHODS=ccall,cwrap

Выход:

      em++ Source.cpp - o source.html - sEXPORTED_FUNCTIONS = _generateKeys, _encrypt, _decrypt - sEXPORTED_RUNTIME_METHODS = ccall, cwrap
wasm - ld: error: C:\Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : VTT for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : VTT for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : VTT for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : VTT for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::InvertibleRSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : VTT for CryptoPP::RSAFunction
wasm - ld : error : C : \Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o: undefined symbol : vtable for CryptoPP::RSAFunction
wasm - ld : error : too many errors emitted, stopping now(use - error - limit = 0 to see all errors)
em++ : error : 'C:/Users//emsdk/upstream/bin\wasm-ld.exe -o source.wasm C:\Users\\AppData\Local\Temp\emscripten_temp_ip2v73bv\Source_0.o -LC:\Users\\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --strip-debug --export-if-defined=generateKeys --export-if-defined=encrypt --export-if-defined=decrypt --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export=__get_temp_ret --export=__set_temp_ret --export=malloc --export=free --export=__cxa_is_pointer_type --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed(returned 1)

0 ответов

Другие вопросы по тегам