CLion 和 Crypto++ 库

CLion and Crypto++ library

不久前,我在 Visual Studio 2015 年开始编写我的应用程序,在设置所有库依赖项时没有遇到任何问题。

现在,我决定转向 CLion。但是我的应用程序依赖于 cryptopp 库,我需要在我的 CLion 项目中 link。

目前,我面临大量 undefined reference 错误

undefined reference to `CryptoPP::Integer::Integer(char const*)'
undefined reference to `CryptoPP::Integer::Integer(char const*)'
undefined reference to `CryptoPP::Integer::Integer(char const*)'
undefined reference to `CryptoPP::DH_Domain<CryptoPP::DL_GroupParameters_GFP_DefaultSafePrime, CryptoPP::EnumToType<CryptoPP::CofactorMultiplicationOption, 0> >::AccessGroupParameters()'
undefined reference to `CryptoPP::DH_Domain<CryptoPP::DL_GroupParameters_GFP_DefaultSafePrime, CryptoPP::EnumToType<CryptoPP::CofactorMultiplicationOption, 0> >::GetGroupParameters() const'
undefined reference to `CryptoPP::DH_Domain<CryptoPP::DL_GroupParameters_GFP_DefaultSafePrime, CryptoPP::EnumToType<CryptoPP::CofactorMultiplicationOption, 0> >::GetGroupParameters() const'
[..]

我确实在我的 CMakeLists 中设置了包含目录:

set(EXTERN_LIBS E:/dev/libs)

include_directories(${EXTERN_LIBS} ${EXTERN_LIBS}/include)
link_directories(${EXTERN_LIBS})

然而,我仍然无法让它工作。

我正在为我的项目使用 MinGW。这是设置和版本的预览:

如何在 CLion 中将 cryptopp 库正确添加到我的项目中?

我认为我们可能已经在 Commit e4cef84883b2. You should work from Master or perform a git pull, and then uncomment the define for CRYPTOPP_NO_CXX11 in config.h : 65(左右)清除了大部分 MinGW/C++11 问题:

// Define CRYPTOPP_NO_CXX11 to avoid C++11 related features shown at the
// end of this file. Some compilers and standard C++ headers advertise C++11
// but they are really just C++03 with some additional C++11 headers and
// non-conforming classes. You might also consider `-std=c++03` or
// `-std=gnu++03`, but they are required options when building the library
// and all programs. CRYPTOPP_NO_CXX11 is probably easier to manage but it may
// cause -Wterminate warnings under GCC. MSVC++ has a similar warning.
// Also see https://github.com/weidai11/cryptopp/issues/529
// #define CRYPTOPP_NO_CXX11 1

我认为问题是,您遇到了与 Windows 相关的问题及其缺乏适当的 C++11 支持,但您是间接得到它们。它们是间接的,因为 MinGW 和 GCC 位于顶部。 MinGW 和 GCC 不可能提供 C++11,因为底层平台不能。

我认为此时最好的选择是定义 CRYPTOPP_NO_CXX11。我不相信我们可以像在 Windows 上那样为您做这件事,因为我们需要访问的定义隐藏在 MinGW 和 GCC 后面。我们还有一些 MSVC++ 错误需要解决。

这是我们在 Windows 上的做法,但我们无法访问 MinGW 中的这些定义(来自 config.h : 950):

// Dynamic Initialization and Destruction with Concurrency ("Magic Statics")
// MS at VS2015 with Vista (19.00); GCC at 4.3; LLVM Clang at 2.9; Apple Clang at 4.0; Intel 11.1; SunCC 5.13.
// Microsoft's implementation only works for Vista and above, so its further
// limited. http://connect.microsoft.com/VisualStudio/feedback/details/1789709
#if (CRYPTOPP_MSC_VERSION >= 1900) && ((WINVER >= 0x0600) || (_WIN32_WINNT >= 0x0600)) || \
    (CRYPTOPP_LLVM_CLANG_VERSION >= 20900) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40000) || \
    (__INTEL_COMPILER >= 1110) || (CRYPTOPP_GCC_VERSION >= 40300) || (__SUNPRO_CC >= 0x5130)
# define CRYPTOPP_CXX11_DYNAMIC_INIT 1
#endif // Dynamic Initialization compilers

如果你定义了CRYPTOPP_NO_CXX11,那么下面的不会被定义,这样你就可以避免问题:CRYPTOPP_CXX11_DYNAMIC_INIT, CRYPTOPP_CXX11_SYNCHRONIZATION,和 CRYPTOPP_CXX11_ATOMICS.


第二个问题,关于Clion和Cmake的问题,解决如下。我们使用我们的 Autotools 和 Cmake 文件设置一个单独的 GitHub。 Autotools 文件位于 cryptopp-autotools, and the Cmake files are at cryptopp-cmake.

存储库在我的 GiHub 中,因为编写库并提供 Crypto++ GitHub 的魏戴更愿意避免这种管理方式。逻辑分离还有助于建立逻辑边界,因此人们知道 Autotools 和 CMake 不是官方 Crypto++ 发行版的一部分。

社区负责Autotools和Cmake,我们会和社区一起解决问题。如果社区投入工作,那么 Autotools 和 Cmake 将会改进。如果 Autotools 或 CMake 变得稳定,那么我们会将包含这些文件的压缩包添加到官方发行版中。

目前Autotools和Cmake都处于需要改进的状态。 Cmake 的问题在维基上的 CMake | Current Status 中有详细说明。 Autotools 的问题并没有真正记录下来,因为我与发行版维护人员一起工作。这有点像我们知道问题是什么,但大多数其他人不知道。