【问题标题】:How to build Apache ActiveMQ-CPP (and APR) on Windows?如何在 Windows 上构建 Apache ActiveMQ-CPP(和 APR)?
【发布时间】:2017-07-26 18:01:12
【问题描述】:

我正在尝试获取一些用 C++ 编写的功能,以与位于 Linux 机器上的 Apache ActiveMQ(本机使用 JMS)进行通信。为了建立这种联系,我尝试在我的 Windows 7 机器(开发机器)上设置 Apache ActiveMQ-CPP,但我目前面临一些主要问题。

据我了解,ActiveMQ-CPP 依赖于 Apache Portable Runtime/APR,如 here 所述。我的问题是,我什至无法构建 APR,因此没有开始使用 ActiveMQ-CPP。我已经遵循this guide 的信函,在并行目录中设置,将版本名称重命名为标准名称并将启动项目更改为 libaprutil(使用动态库),但没有任何运气。在构建 APR 解决方案时,27 个项目中只有 13 个成功。我还尝试使用静态 aprutil 项目作为启动项目来构建解决方案,但没有任何改进。

解决方案是确保为 Visual Studio 6 提供更广泛的兼容性,因此我怀疑使用 Visual Studio 2010 是造成我的问题的原因。即使升级项目应该是可能的(如 APR 文档所述),在使用升级助手并尝试构建整个解决方案之后,我在项目中有几个(我认为是)缺少依赖项,请参阅第一个屏幕转储。许多错误与文件 iconv_module.obj (error LNK2019: unresolved external symbol xxx referenced in function _iconv_getpath C:\work\apr-iconv\iconv_module.obj) 相关,从下方工具提示中可以看出,该文件应在 C:\work\apr-iconv 中找到。该文件实际上位于不同的子文件夹中,具体取决于构建格式(我选择了“Release”和“Win32”),但我不确定这是否真的是一个问题。

我应该提到,我对 C++ 完全陌生,并且对 C 的经验非常有限,所以也许只是我不理解手动链接的依赖项......如果打开提到的文件并查看错误消息中声明的函数,但是,代码显然也有问题,所以可能不是依赖关系,请参阅两个屏幕转储。

关于可能的解决方案,我被建议尝试手动构建每个项目,而不是一次构建整个解决方案,因此首先构建不依赖于任何东西的库,依此类推。然而,这也没有成功。

还应该可以使用命令行来构建项目,这对某些人来说是成功的(link)。在较新版本的 Visual Studio 中,“msdev”似乎被“devenv”取代,但即使考虑到这一点,在使用查找和替换后,构建仍然会抱怨“找不到 msdev”......也许不是最好的修复,是吧?

在搜索有类似问题的帖子时,我肯定并不孤单,但不幸的是,没有一个建议的解决方案对我有用。我看过的一些帖子是:Compile Apache APR on WindowsActiveMQ-CPP and Visual Studio 2003

你们有没有使用较新版本的 Visual Studio 或 Windows 上的命令行构建 APR 的经验?或者更重要的是,让 ActiveMQ-CPP 在 Windows 上工作?

截图:

【问题讨论】:

    标签: c++ visual-studio activemq apr activemq-cpp


    【解决方案1】:

    我能够使用 ActiveMQ 源中的 README.txt 中的说明通过命令行构建 APR。

    6.2.1 APR 库。

    APR 仅由 Apache 软件基金会以源代码形式提供。您需要通过从以下位置下载最新版本来从源代码构建一个库:

    http://apr.apache.org/
    

    在撰写本文时,最新版本是 v1.5.2,建议使用它,因为它的构建支持文件可与 Visual Studio 2010 工具配合使用。

    APR 是使用其提供的 Make 文件从命令行构建的。在构建库时,您需要确保您处于正确的环境中以生成所需的架构构建(x64 或 win32)。您可以使用 Visual Studio 开始菜单位置下的快捷方式打开正确的命令行(例如 Visual Studio 2010 / Visual Studio Tools / Visual Studio x64 win 64 Command Prompt

    在正确的命令提示符下切换到 APR 源代码所在的目录(例如:C:\APR),然后运行库的构建以生成所需的 ARCH 构建。

    对于安装到正确分发目录的 32 位库,运行:

    nmake -f Makefile.win ARCH="Win32 Release" PREFIX=C:\dist\APR\x64 buildall install clean
    

    对于库的 64 位版本,请使用该命令。

    nmake -f Makefile.win ARCH="x64 Release" PREFIX=C:\dist\APR\x64 buildall install clean
    


    我做到了:

    转到:开始菜单 > 所有程序 > Visual Studio 2017 > Visual Studio 工具 并启动开发者命令提示符。从那里导航到 APR 源的位置并运行相应的命令。在 64 位 Windows 7 上,我运行 nmake -f Makefile.win ARCH="Win32 Release" PREFIX=C:\dist\APR\x64 buildall install clean

    更通用:

    转到:开始菜单 > 所有程序 > Visual Studio 2017 > Visual Studio 工具 > VC 并启动您正在构建的体系结构的命令提示符。如果为 x64 架构构建,则使用 nmake -f Makefile.win ARCH="x64 Release" PREFIX=C:\dist\APR\x64 buildall install clean 继续上述步骤。

    这样就成功构建了APR,放到C:\dist\APR\x64


    然后在 Visual Studio 中确保 C:\dist\APR\x64\includes 在项目属性的 Additional Includes 中链接。

    1. 右键单击您的项目并选择属性
    2. 展开配置属性
    3. 扩展 C/C++
    4. 选择常规
    5. 编辑其他包含目录并添加 C:\path\to\APR\arch\include
    6. 应用更改

    此时构建会产生以下错误(请参阅下面的解决方案):

    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(53): error C2039: 'auto_ptr': is not a member of 'std'
    1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\include\sstream(13): note: see declaration of 'std'
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(53): error C2143: syntax error: missing ';' before '<'
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(53): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(53): error C2238: unexpected token(s) preceding ';'
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(55): error C2614: 'decaf::internal::security::SRNGData': illegal member initialization: 'random' is not a base or member
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(74): error C2039: 'random': is not a member of 'decaf::internal::security::SRNGData'
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(45): note: see declaration of 'decaf::internal::security::SRNGData'
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(74): error C2228: left of '.reset' must have class/struct/union
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(96): error C2039: 'random': is not a member of 'decaf::internal::security::SRNGData'
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(45): note: see declaration of 'decaf::internal::security::SRNGData'
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(96): error C2228: left of '.get' must have class/struct/union
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(99): error C2039: 'random': is not a member of 'decaf::internal::security::SRNGData'
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(45): note: see declaration of 'decaf::internal::security::SRNGData'
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(99): error C2227: left of '->setSeed' must point to class/struct/union/generic type
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(117): error C2039: 'random': is not a member of 'decaf::internal::security::SRNGData'
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(45): note: see declaration of 'decaf::internal::security::SRNGData'
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(117): error C2228: left of '.get' must have class/struct/union
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(140): error C2039: 'random': is not a member of 'decaf::internal::security::SRNGData'
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(45): note: see declaration of 'decaf::internal::security::SRNGData'
    1>..\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp(140): error C2227: left of '->nextBytes' must point to class/struct/union/generic type
    

    要解决错误,请在文件顶部添加#include &lt;memory&gt;,编辑activemq-cpp-library-3.9.4\src\main\decaf\internal\security\windows\SecureRandomImpl.cpp

    添加上述包含后重新构建会成功构建 ActiveMQ。

    输出到:activemq-cpp-library-3.9.4\vs2010-build\\Win32\Release\libactivemq-cpp.lib

    【讨论】:

    • 还有一件重要的事情要记住,那就是以 Administrator 身份运行 Developer Command Promt !否则会使“nmake”无法构建...我还想强调,应该在“apr”目录中构建“Makefile.wim”,而不是“apr-util”。有趣的是,我没有你描述的最后一个问题......我不明白为什么 Apache 没有将这些说明放在 APR 官方网站上......好吧,无论如何......非常感谢!在很长一段时间没有进一步行动之后,我终于设法构建了 APR 和 ActiveMQ-CPP!你就是那个男人;)
    • 对于那些试图在解决方案中构建示例项目的人,您还必须在项目属性中包含构建 APR 库。替换上面的步骤 3),改为单击 VC++ 目录,并将 C:\dist\APR\x64\lib 文件夹添加到 x64 项目的 库目录 中(这是在 Visual Studio 2010 中)。对于像我这样的 C++ 新手,我还想强调,“Release”和“Debug”库之间存在重大区别,应该系统地使用正确的库。
    【解决方案2】:

    我使用 NuGet 存储库中提供的 APR 在 Visual Studio 2012 pro 上构建了 ActiveMQ。就我而言,某些配置无法链接。项目属性的链接部分中的简单路径修复将使其工作。

    我还没有设法让单元测试运行。

    【讨论】:

      猜你喜欢
      • 2011-12-06
      • 1970-01-01
      • 2014-06-09
      • 1970-01-01
      • 2017-08-18
      • 1970-01-01
      • 2015-07-31
      • 2014-12-12
      • 2012-09-18
      相关资源
      最近更新 更多