error C3641 - using Crypto++ with .Net Framework

Answered error C3641 - using Crypto++ with .Net Framework

  • Tuesday, July 31, 2007 3:48 AM
     
     

    i m trying to using Crypto++ with .Net framework in VC2005 Express Edition.

    But when i starting inlcuding same header file which provide by Crypto++ , like "rsa.h",

    i m getting the compile time error as following,

     

    Code Snippet

    c:\program files\cryptopp\include\cryptlib.h(288) : error C3641: 'CryptoPP::NameValuePairs::ThrowIfTypeMismatch' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe

    1>c:\program files\cryptopp\include\misc.h(530) : error C3861: '_rotl16': identifier not found

    1>c:\program files\cryptopp\include\misc.h(536) : error C3861: '_rotr16': identifier not found

    1>c:\program files\cryptopp\include\misc.h(542) : error C3861: '_rotl16': identifier not found

    1>c:\program files\cryptopp\include\misc.h(548) : error C3861: '_rotr16': identifier not found

    1>c:\program files\cryptopp\include\misc.h(553) : error C3861: '_rotl16': identifier not found

    1>c:\program files\cryptopp\include\misc.h(558) : error C3861: '_rotr16': identifier not found

    1>c:\program files\cryptopp\include\misc.h(564) : error C3861: '_rotl8': identifier not found

    1>c:\program files\cryptopp\include\misc.h(570) : error C3861: '_rotr8': identifier not found

    1>c:\program files\cryptopp\include\misc.h(576) : error C3861: '_rotl8': identifier not found

    1>c:\program files\cryptopp\include\misc.h(582) : error C3861: '_rotr8': identifier not found

    1>c:\program files\cryptopp\include\misc.h(587) : error C3861: '_rotl8': identifier not found

    1>c:\program files\cryptopp\include\misc.h(592) : error C3861: '_rotr8': identifier not found

    1>c:\program files\cryptopp\include\pubkey.h(489) : error C3641: 'CryptoPP::P1363_MGF1::StaticAlgorithmName' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe

    1>c:\program files\cryptopp\include\pkcspad.h(58) : error C3641: 'CryptoPP::PKCS1v15_SignatureMessageEncodingMethod::StaticAlgorithmName' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe

    1>c:\program files\cryptopp\include\sha.h(14) : error C3641: 'CryptoPP::SHA1::StaticAlgorithmName' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe

    1>c:\program files\cryptopp\include\sha.h(25) : error C3641: 'CryptoPP::SHA256::StaticAlgorithmName' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe

    1>c:\program files\cryptopp\include\sha.h(33) : error C3641: 'CryptoPP::SHA224::Transform' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe

    1>c:\program files\cryptopp\include\sha.h(34) : error C3641: 'CryptoPP::SHA224::StaticAlgorithmName' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe

    1>c:\program files\cryptopp\include\sha.h(45) : error C3641: 'CryptoPP::SHA512::StaticAlgorithmName' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe

    1>c:\program files\cryptopp\include\sha.h(53) : error C3641: 'CryptoPP::SHA384::Transform' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe

    1>c:\program files\cryptopp\include\sha.h(54) : error C3641: 'CryptoPP::SHA384::StaticAlgorithmName' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe

    1>c:\program files\cryptopp\include\emsa2.h(62) : error C3641: 'CryptoPP::EMSA2Pad::StaticAlgorithmName' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe

    1>C:\Program Files\CryptoPP\include\rsa.h(123) : error C3641: 'CryptoPP::RSA::StaticAlgorithmName' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe

    1>C:\Program Files\CryptoPP\include\rsa.h(143) : error C3641: 'CryptoPP::RSA_ISO::StaticAlgorithmName' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe

     

     

    beside that , i check the setting of "Common Language Runtime support" , it already set as "/clr : pure".

     

    can someone help me~~~ many thanks

All Replies

  • Tuesday, July 31, 2007 11:01 AM
     
     
    And are you sure that the Crypto++ is compatible with .NET ?

     

  • Tuesday, July 31, 2007 2:23 PM
    Moderator
     
     

    You've got an imcompatible set of options.  You're apparently building with /clrTongue Tiedafe or /clrStick out tongueure.  Neither of these will permit you to call unmanaged code.  So, first off, you need to change your project settings to either generate native code (no /clr option at all), or to just /clr (neither pure nor safe).

     

    Second, if you are using /clr, you probably need to surround all Crypto++ #includes with directives to turn off managed code for those files:

     

    #pragma managed(push,off)

    #include "rsa.h"

    #pragma managed(pop)

     

    The above assumes that you've built Crypto++ as unmanaged code, which I'm sure is the default if you've simply downloaded Crypto++ and built it using the supplied project file.

     

  • Wednesday, August 01, 2007 1:36 AM
     
     

    Dear Carl Daniel,

     

    First of all, thank u for ur reply.

     

    But after i follow ur suggestion,

    i get another link error again,

    Code Snippet

    1>Linking...

    1>LIBCMT.lib(__ctype.obj) : error LNK2005: _isalpha already defined in MSVCRT.lib(MSVCR80.dll)

    1>LIBCMT.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in MSVCRT.lib(MSVCR80.dll)

    1>LIBCMT.lib(tidtable.obj) : error LNK2005: __decode_pointer already defined in MSVCRT.lib(MSVCR80.dll)

    1>LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRT.lib(MSVCR80.dll)

    1>LIBCMT.lib(typinfo.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in MSVCRT.lib(ti_inst.obj)

    1>LIBCMT.lib(typinfo.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in MSVCRT.lib(ti_inst.obj)

    1>LIBCMT.lib(invarg.obj) : error LNK2005: __invalid_parameter_noinfo already defined in MSVCRT.lib(MSVCR80.dll)

    1>LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRT.lib(MSVCR80.dll)

    1>LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRT.lib(MSVCR80.dll)

    1>LIBCMT.lib(_tolower.obj) : error LNK2005: _tolower already defined in MSVCRT.lib(MSVCR80.dll)

    1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

    1>D:\vc2005\RSASSA-PSS-TestBed-2005\Release\RSASSA-PSS-TestBed-2005.exe : fatal error LNK1169: one or more multiply defined symbols found

     

     

    and it seem like something is alrady defibe in msvcprtd.lib and MSVCRTD.

     

    once again , thank u for ur help.

  • Wednesday, August 01, 2007 2:59 AM
    Moderator
     
     
    Now you have a mixture of runtime library settings - specifically, something's been compiled with -MT, while something else has been compiled with -MD.  Make sure that you build everything with the same runtime library settings.

     

  • Wednesday, August 01, 2007 5:46 AM
     
     

    but seem like Crypto++ have to compile with "-MT"

    and my windows from app have to compile with "MD".

     

    what should i do ??? Sad

  • Thursday, August 02, 2007 2:58 AM
    Moderator
     
     Answered

    Crypto++ can be compiled with -MD: just change the project settings.

     

    Unless you're using managed code (and it sounds like you're not), then your windows app can be built with -MT.  If you're using MFC, then to link the CRT statically (i.e. use -MT) you must also link MFC statically (and vice-versa for linking dynamically).

  • Thursday, August 02, 2007 9:57 AM
     
     

    thank u very much.

    Stick out tongue i didn't that Crypto++ also can compile wirh -MD