Failed to compile shared with error: undefined symbol: _ZTIN8CryptoPP21SimpleKeyingInterfaceE

30 views
Skip to first unread message

Cristian Rolando Reyes Chapoñan

unread,
Aug 16, 2022, 1:54:04 PM8/16/22
to Crypto++ Users

Hello everyone, a question when I try to use the package and compile it in shared form (.so)
and I want to read it I get this:
undefined symbol: _ZN8CryptoPP21SimpleKeyingInterface6SetKeyEPKhmRKNS_14NameValuePairsE

in which I investigate and it says that I have to compile it in such a way that the symbols must be together with the compiled one, I have tried everything to compile it according to the forums and documentations with the command "-g" or "-O2" but I still cannot read the file

My build commands are these:

g++ -DNDEBUG -g -O2 -Wall -Wextra -o node.o node.cpp -l:libcryptopp.a
g++ -shared -o node.so node.o

I would be very grateful for your great help.

Versions install:
libcrypto++6
libcrypto++-utils
libcrypto++-dev
libcrypto++-doc
libcrypto++6-dbg

My code:
File name: node.cpp

`
#include "iostream" // I write it like this since it is not shown on this page
#include "string" // I write it like this since it is not shown on this page

#include "cryptopp/modes.h"
#include "cryptopp/aes.h"
#include "cryptopp/filters.h"
#include "cryptopp/hex.h"

using namespace std;
using namespace CryptoPP;

string node (string text){
string plain = params;
// Our input:
// Note: the input was previously generated by the same cipher
string keyImput = "ABCDEF";
string ivImput = "ABCDF";
string cadenaInput = plain;

byte iv_[CryptoPP::AES::BLOCKSIZE] = {}; // this decoder would transform our std::string into raw hex: CryptoPP::HexDecoder decoder; decoder.Put((byte*)ivImput.data(), ivImput.size()); decoder.MessageEnd(); decoder.Get(iv_, sizeof(iv_)); std::string cadenaInput_raw; { CryptoPP::HexDecoder decoder; decoder.Put((byte*)cadenaInput.data(), cadenaInput.size()); decoder.MessageEnd(); long long size = decoder.MaxRetrievable(); cadenaInput_raw.resize(size); decoder.Get((byte*)cadenaInput_raw.data(), cadenaInput_raw.size()); } byte key_[CryptoPP::AES::DEFAULT_KEYLENGTH]; { CryptoPP::HexDecoder decoder; decoder.Put((byte*)keyImput.data(), keyImput.size()); decoder.MessageEnd(); decoder.Get(key_, sizeof(key_)); } string decrypted_text; try { CBC_Mode<AES>::Decryption d; d.SetKeyWithIV(key_, sizeof(key_), iv_); StringSource s(cadenaInput_raw, true, new StreamTransformationFilter( d, new StringSink(decrypted_text) ) // StreamTransformationFilter ); // StringSource return decrypted_text; } catch( CryptoPP::Exception& e ) { std::cerr << e.what() << std::endl; exit(1); }

}

extern "C" string dencrypnode (string params){
return node(params);
}

int main (){
string keyImput;
string retorno;
std::cout << "\nIngrese llave key : ";
std::cin >> keyImput;
retorno = dencrypnode(keyImput);
std::cout << retorno << std::endl;
return 0;
}

`

Jeffrey Walton

unread,
Aug 16, 2022, 10:25:06 PM8/16/22
to Crypto++ Users List
On Tue, Aug 16, 2022 at 1:54 PM Cristian Rolando Reyes Chapoñan
<creyesc...@gmail.com> wrote:
>
> Hello everyone, a question when I try to use the package and compile it in shared form (.so)
> and I want to read it I get this:
> undefined symbol: _ZN8CryptoPP21SimpleKeyingInterface6SetKeyEPKhmRKNS_14NameValuePairsE
>
> in which I investigate and it says that I have to compile it in such a way that the symbols must be together with the compiled one, I have tried everything to compile it according to the forums and documentations with the command "-g" or "-O2" but I still cannot read the file
>
> My build commands are these:
>
> g++ -DNDEBUG -g -O2 -Wall -Wextra -o node.o node.cpp -l:libcryptopp.a
> g++ -shared -o node.so node.o
>
> I would be very grateful for your great help.
>
> Versions install:
> libcrypto++6
> libcrypto++-utils
> libcrypto++-dev
> libcrypto++-doc
> libcrypto++6-dbg
>
> My code:
> File name: node.cpp
>
> #include "cryptopp/modes.h"
> #include "cryptopp/aes.h"
> #include "cryptopp/filters.h"
> #include "cryptopp/hex.h"

I think you are missing <seckey.h>.

You might also be interested in https://cryptopp.com/wiki/Wrapper_DLL .

Jeff

Cristian Rolando Reyes Chapoñan

unread,
Aug 18, 2022, 2:04:27 PM8/18/22
to Crypto++ Users
Hello Jeff, thanks for the answer, I solved it by also importing the library when compiling the shared one, I put my codes so that someone wants to try to do the same as me.

Make file.o
=======
g++ -c -g3 -Wall -Werror -Wextra -fpic file.cpp -l:libcryptopp.a

Make file.so
========
g++ -shared -o file.so file.o -lcryptopp -lpthread


Now you can get your shared c++ library so you can use it in any language, in this case I use .so since I am in a linux environment.


Thanks for the answer, regards,
Reply all
Reply to author
Forward
0 new messages