【问题标题】:Building Crypto++ 5.6.2 with Cygwin x86_64使用 Cygwin x86_64 构建 Crypto++ 5.6.2
【发布时间】:2014-02-01 20:47:59
【问题描述】:

我正在尝试使用 Cygwin x86_64 构建 CryptoPP,但我在使用 osrng.cpp 时遇到了一些问题。

我正在使用 gcc 的 C++ 编译器,我在 line 50 of osrng.cpp 收到以下错误

$ make
g++ -DNDEBUG -g -O2 -march=native -pipe -c osrng.cpp
osrng.cpp: In constructor ‘CryptoPP::MicrosoftCryptoProvider::MicrosoftCryptoProvider()’:
osrng.cpp:50:80: error: invalid conversion from ‘CryptoPP::MicrosoftCryptoProvider::ProviderHandle* {aka long unsigned int*}’ to ‘HCRYPTPROV* {aka long long unsigned int*}’ [-fpermissive]
  if(!CryptAcquireContext(&m_hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
                                                                                ^
In file included from /usr/include/w32api/windows.h:95:0,
                 from osrng.cpp:19:
/usr/include/w32api/wincrypt.h:646:26: error:   initializing argument 1 of ‘WINBOOL CryptAcquireContextA(HCRYPTPROV*, LPCSTR, LPCSTR, DWORD, DWORD)’ [-fpermissive]
   WINIMPM WINBOOL WINAPI CryptAcquireContextA(HCRYPTPROV *phProv,LPCSTR szContainer,LPCSTR szProvider,DWORD dwProvType,DWORD dwFlags);
                          ^
GNUmakefile:208: recipe for target 'osrng.o' failed
make: *** [osrng.o] Error 1

我之前在32位版本的Cygwin下成功编译过整个东西。

对于 64 位版本,我该如何解决这个问题?

编辑 正如@Yakovanswer 所建议的,我在line 30 of osrng.h 中将if defined(_WIN64)if defined(__x86_64__) 替换为if。 可悲的是,我立即遇到了下一个问题,由以下错误指示:

$ make
g++ -DNDEBUG -g -O2 -march=native -pipe -c fipstest.cpp
In file included from dll.h:30:0,
                 from fipstest.cpp:8:
osrng.h:34:19: error: expected ‘;’ at end of member declaration
  typedef unsigned __int64 ProviderHandle; // type HCRYPTPROV, avoid #include <windows.h>
                   ^
osrng.h:34:27: error: ‘ProviderHandle’ does not name a type
  typedef unsigned __int64 ProviderHandle; // type HCRYPTPROV, avoid #include <windows.h>
                           ^
osrng.h:38:2: error: ‘ProviderHandle’ does not name a type
  ProviderHandle GetProviderHandle() const {return m_hProvider;}
  ^
osrng.h:40:2: error: ‘ProviderHandle’ does not name a type
  ProviderHandle m_hProvider;
  ^
GNUmakefile:208: recipe for target 'fipstest.o' failed
make: *** [fipstest.o] Error 1

【问题讨论】:

    标签: gcc compiler-errors cygwin x86-64 crypto++


    【解决方案1】:

    值得庆幸的是,GCC 错误消息在最近的版本中得到了显着改善。 {aka}s 告诉您longlong long 之间不匹配。请记住,Win64 是 LLP64:long 仍然只有 32 位,并且您需要一个 long long 来匹配指针的大小。大多数(全部?)其他 64 位平台都是 LP64,这意味着 long 匹配指针的大小。

    在这种特殊情况下,请参阅osrng.h 中的if defined(_WIN64);您需要将该条件更改为 if defined(__x86_64__)

    您也可能会遇到__int64 类型的问题。将它们替换为long long。 (出现在hereherehere。)

    【讨论】:

    • 我试过了,但现在我遇到了下一个错误。我已经相应地更新了问题。
    • _int64s 替换为long long。您可能还需要在代码的其他地方进行类似的更改; grep -r _WIN64 应该可以帮助您找到其他可能的情况。
    • 成功了。我发布了一个编辑,将您的最后一条评论包含在答案中。
    【解决方案2】:

    您可能还会发现word64 很有用。来自 Crypto++ 的config.h

    #if defined(_MSC_VER) || defined(__BORLANDC__)
        typedef unsigned __int64 word64;
        #define W64LIT(x) x##ui64
    #else
        typedef unsigned long long word64;
        #define W64LIT(x) x##ULL
    #endif
    

    那里也有几个 Cygwin 定义。但它们看起来并不有趣。例如:

    #ifndef TYPE_OF_SOCKLEN_T
    #   if defined(_WIN32) || defined(__CYGWIN__)
    #       define TYPE_OF_SOCKLEN_T int
    #   else
    #       define TYPE_OF_SOCKLEN_T ::socklen_t
    #   endif
    #endif
    
    #if defined(__CYGWIN__) && defined(PREFER_WINDOWS_STYLE_SOCKETS)
    #   define __USE_W32_SOCKETS
    #endif
    

    (对这里的评论感到抱歉。它太适合放在小评论块中)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多