在 vs 2010 c++ 中构建 log4cxx

发布于 2024-12-20 09:06:10 字数 1002 浏览 1 评论 0原文

这让我发疯,我正在尝试构建 log4cxx 库以便在我一直在使用的 C++ 项目中使用。我在运行 VS2010 Express C++ 版本的 win7 主机上。我已按照 log4cxx 说明 ( ) 进行操作,包括下载 apr 和 apr-util 并主题化 .hw 文件,但不幸的是,当我尝试加载 log4cxx.dsw 解决方案并将其转换为当前的 VS 时,我收到一个错误,试图构建 apr.apr/dsw 和一堆其他相关的 .dsw 文件。有什么建议吗?

具体来说,我看到的是:

The Project file 'C:\...projects\apr-util\xml\expat\lib\xml.dsp' cannot be loaded. Do you want to remove the unloadable project from the solution?

我在一堆其他 .dsp 文件中看到了这一点。

然后在VC的输出框中:

C:\Users\x\Documents\Visual Studio 2010\Projects\apr\apr.dsp : error  : Project upgrade failed.

C:\Users\x\Documents\Visual Studio 2010\Projects\apr-util\xml\expat\lib\xml.dsp : error  : Project upgrade failed.

C:\Users\x\Documents\Visual Studio 2010\Projects\apr-util\aprutil.dsp : error  : Project upgrade failed.

C:\Users\x\Documents\Visual Studio 2010\Projects\apache-log4cxx-0.10.0\projects\log4cxx.dsp : error  : Project upgrade failed.

谢谢

文件位于正确的路径中。

This is driving me crazy, I'm trying to building the log4cxx library in order to use in a c++ project I've been using. I'm on a win7 host running VS2010 express c++ edition. I've followed the directions per the log4cxx directions ( ) including downloading apr
and apr-util and motifying the .hw files, but I unfortunately, when ever I try to load the log4cxx.dsw solution and convert it to the current VS, I receive an error trying to build apr.apr/dsw and a bunch of other dependent .dsw files. Any suggestions?

Specifically, what I am seeing is:

The Project file 'C:\...projects\apr-util\xml\expat\lib\xml.dsp' cannot be loaded. Do you want to remove the unloadable project from the solution?

I see this for a bunch of other .dsp files.

then in the output box in VC:

C:\Users\x\Documents\Visual Studio 2010\Projects\apr\apr.dsp : error  : Project upgrade failed.

C:\Users\x\Documents\Visual Studio 2010\Projects\apr-util\xml\expat\lib\xml.dsp : error  : Project upgrade failed.

C:\Users\x\Documents\Visual Studio 2010\Projects\apr-util\aprutil.dsp : error  : Project upgrade failed.

C:\Users\x\Documents\Visual Studio 2010\Projects\apache-log4cxx-0.10.0\projects\log4cxx.dsp : error  : Project upgrade failed.

Thanks

The files are in the correct path.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

橘虞初梦 2024-12-27 09:06:10

您必须按照以下步骤让 log4cxx(版本 0.10.0)与 VS2010 一起使用:

  1. 此处
  2. 此处下载 apr 和 apr-util ZIP 包,
  3. 将 log4cxx、apr 和 apr-util 解压到同一目录下 更改
  4. 将 apr_VERSION 和 apr-util_VERSION 文件夹重命名为 apr 和 apr-util,从而生成一个包含三个文件夹的目录:apache-log4cxx-0.10.0、apr 和 apr-util
  5. 为 log4cxx 目录并执行 configure.bat
  6. 更改为 apr- util/include direcotry 并在您选择的文本编辑器中打开 apu.hw
  7. 找到条目 #define APU_HAVE_APR_ICONV,将其设置为 0 并保存文件
  8. 从同一目录打开 apr_ldap.hw 并找到条目 #define APR_HAS_LDAP,将其设置为 0 并保存该文件也是如此。
  9. 切换到 log4cxx/projects 目录并使用 VS2010 打开 log4cxx.dsw。对于每个项目(apr、apr-util、log4cxx、xml),用 yes/ok 回答 VS2010 的转换提示。

好的,如果你现在点击构建,那么你将看到大约 2000 个错误,这就是有趣且“困难”的部分开始的地方:

  • Ctrl+F 并找到“LOG4CXX_LIST_DEF”宏的每个条目。您必须将这些条目移出其相关类并移至同一类之前。有时您也需要移动 typedef 或在宏之前添加类。

一些示例:

    // telnetadapter.h
    ...
    typedef log4cxx::helpers::SocketPtr Connection;
    LOG4CXX_LIST_DEF(ConnectionList, Connection);
    class LOG4CXX_EXPORT TelnetAppender : public AppenderSkeleton
    ...

    // appender.h
    ...
    class Appender;
    LOG4CXX_PTR_DEF(Appender);
    LOG4CXX_LIST_DEF(AppenderList, AppenderPtr);

    class Layout;
    typedef log4cxx::helpers::ObjectPtrT<Layout> LayoutPtr;

    ...

    class LOG4CXX_EXPORT Appender :
                public virtual spi::OptionHandler
    {
    ...
  • 如果编译器抱怨 KeySet 不是 LoggingEvent 的成员,只需删除作用域(由于我们在上一步中将类型移至类外部,因此这些类型不再位于类内部)

示例:

   // old
   LoggingEvent::KeySet set;
   // new
   KeySet set;
  • 如果编译器抱怨 insert_iterator 不在命名空间 std 中,请将 #include 添加到源文件的 include 部分。

  • 最后但并非最不重要的一点是,右键单击 log4cxx 项目并选择“添加引用”并选择其他 3 个项目作为引用


希望这对您和其他一些人有帮助:) ...如果您需要整个解决方案或其他文件,请告诉我!

我在 this Lex LI 的博客文章。

编辑:
您可以从我的保管箱下载我的 VS2010 解决方案和源代码:
https://www.dropbox.com/s/rn5d0044jzgzwyf/log4cxx_vs2010.7z

You have to follow these steps to get log4cxx (Version 0.10.0) working with VS2010:

  1. Download the latest log4cxx package from here
  2. Download apr and apr-util ZIP packages from here
  3. Extract log4cxx, apr und apr-util to the same directory
  4. Rename the apr_VERSION and apr-util_VERSION folder to apr and apr-util resulting in a directory with three folder: apache-log4cxx-0.10.0, apr and apr-util
  5. Change into the log4cxx directory and execute configure.bat
  6. Change to apr-util/include direcotry and open apu.hw in a texteditor of your choice
  7. Find the entry #define APU_HAVE_APR_ICONV, set it to 0 and save the file
  8. Open apr_ldap.hw from the same directory and find the entry #define APR_HAS_LDAP, set it to 0 and save the file, too.
  9. Change to log4cxx/projects directory and open log4cxx.dsw with VS2010. Answer the converting prompts of VS2010 with yes/ok for each project (apr, apr-util, log4cxx, xml)

Ok if you hit build now then you will see around 2000 errors and that is where the interesting and "hard" part starts:

  • Ctrl+F and find each entry of the "LOG4CXX_LIST_DEF" macro. You have to move these entries out of its related class and right before the same class. Sometimes you need to move a typedef too or add the class right before the macro.

Some examples:

    // telnetadapter.h
    ...
    typedef log4cxx::helpers::SocketPtr Connection;
    LOG4CXX_LIST_DEF(ConnectionList, Connection);
    class LOG4CXX_EXPORT TelnetAppender : public AppenderSkeleton
    ...

    // appender.h
    ...
    class Appender;
    LOG4CXX_PTR_DEF(Appender);
    LOG4CXX_LIST_DEF(AppenderList, AppenderPtr);

    class Layout;
    typedef log4cxx::helpers::ObjectPtrT<Layout> LayoutPtr;

    ...

    class LOG4CXX_EXPORT Appender :
                public virtual spi::OptionHandler
    {
    ...
  • If the compiler complains about KeySet not being member of LoggingEvent, just remove the scope (since we moved the type to outside the class in the previous step, these types no longer are inside the class)

Example:

   // old
   LoggingEvent::KeySet set;
   // new
   KeySet set;
  • If the compiler complains about insert_iterator not being in the namespace std, add #include <iterator> to the include section of the source file.

  • Last but not least, right-click on log4cxx project and select Add References and select the other 3 projects as reference


Hope this helps you and some others :) ... if you need the whole solution or other files, let me know!

I figured out these steps with the enormous help of this blog entry by Lex LI.

EDIT:
You can download my VS2010 solution and source code from my dropbox:
https://www.dropbox.com/s/rn5d0044jzgzwyf/log4cxx_vs2010.7z

无人问我粥可暖 2024-12-27 09:06:10

人们已经成功地通过 2 个步骤转换了 log4cxx:

  • 原始版本 (VS 6) 到 VS 2008
  • VS 2008 到 VS 2010

值得庆幸的是,有人已经将 log4cxx 0.10 作为 Visual Studio 2008 项目提供,网址为 http://www.dreamcubes.com/webdrive/log4cxx_win32/log4cxx -0.10.0-vc2008-June2008.rar。我已经使用 VS 2010 Express 成功构建了该项目。

People have successfully converted log4cxx in 2 steps:

  • original (VS 6) to VS 2008
  • VS 2008 to VS 2010

Thankfully, someone has made log4cxx 0.10 available as a Visual Studio 2008 project at http://www.dreamcubes.com/webdrive/log4cxx_win32/log4cxx-0.10.0-vc2008-June2008.rar. I've built the project successfully with VS 2010 Express.

流年里的时光 2024-12-27 09:06:10

第 1 章官方步骤

我们将按照此处的步骤操作,http ://logging.apache.org/log4cxx/building/vstudio.html。然而,我们必须做出改变以适应windows/VS201*。

  1. 从这里下载更高版本的 log4cxx,即 apache log4cxx 0.10,http://logging.apache .org/log4cxx/download.html

  2. 从下载依赖项https://archive.apache.org/dist/apr/

  3. 官方构建指南是非常容易遵循:

解压apr-1.2.11-win32-src.zip
重命名 apr-1.2.11 apr
解压 apr-util-1.2.10-win32-src.zip
重命名 apr-util-1.2.10 apr-util
cd apache-log4cxx-0.10.0
配置
配置 aprutil
  1. 我建议你在你的开发机器上安装gow,这样你就会有很多类似unix/linux的工具,非常方便。或者如果你有 git,你可以将 git cmd 工具添加到你的环境中。

<前><代码>配置
配置 aprutil

以上2个cmd需要sed.exe,在执行它们之前安装它(gow/git)。
或者您可以手动更改 apu.hw 和 apr_ldap.hw:

打开 apr_ldap.hw 并找到条目 #define APR_HAS_LDAP,将其设置为 0 并保存文件。
打开apu.hw并找到条目#define APU_HAVE_APR_ICONV,将其设置为0并保存文件

第2章构建Log4cxx

  1. 现在我们必须将*.dsw转换为*.cxproj。为了使其顺利进行,只需启动 Visual Studio 201* 并打开 log4cxx.dsw。 VS 会询问您是否要转换所有内容。只需单击“是”即可。

  2. 将 log4cxx 设置为启动项目。

  3. 打开项目 log4cxx 的属性窗口,添加其他 3 个项目作为引用,在这里:
    属性->共同属性->框架和参考文献。
  4. 按 F7,如果看到错误 c2252,这是因为 LOG4CXX_LIST_DEF 定义错误,转到其定义并将其更改为

#define LOG4CXX_LIST_DEF(N, T) typedef std::vector; N

像这样,

旧的:

<前><代码>#define LOG4CXX_LIST_DEF(N, T) \
模板类 LOG4CXX_EXPORT std::allocator; \
模板类 LOG4CXX_EXPORT std::vector; \
typedef std::vector;氮

新的:

#define LOG4CXX_LIST_DEF(N, T) typedef std::vector;氮
  1. 你会遇到另一个关于insert_iterator的错误,只需添加#include<迭代器>到相对文件

  2. 完成!享受你的 log4cxx!

Chapter 1 Official Steps

We are going to follow the steps here, http://logging.apache.org/log4cxx/building/vstudio.html. However, we must make changes to adapt to windows/VS201*.

  1. download later version of log4cxx which is apache log4cxx 0.10 from here, http://logging.apache.org/log4cxx/download.html

  2. download dependencies from https://archive.apache.org/dist/apr/

  3. The official building guideline is quite easy to follow:

unzip apr-1.2.11-win32-src.zip
rename apr-1.2.11 apr
unzip apr-util-1.2.10-win32-src.zip
rename apr-util-1.2.10 apr-util
cd apache-log4cxx-0.10.0
configure
configure-aprutil
  1. i recommand you install gow in your developer machine, then you'll have many unix/linux like tools, very convenient. or if you have git, you can add git cmd tools into your env.
configure
configure-aprutil

above 2 cmd requires sed.exe, install it (gow/git) before execute them.
or you can change apu.hw and apr_ldap.hw manually:

Open apr_ldap.hw and find the entry #define APR_HAS_LDAP, set it to 0 and save the file, too.
Open apu.hw and find the entry #define APU_HAVE_APR_ICONV, set it to 0 and save the file

Chapter 2 Building Log4cxx

  1. Now we have to convert *.dsw to *.cxproj. To make it smooth, just launch Visual Studio 201* and open log4cxx.dsw. VS will ask if you like to convert everything. Simply click Yes.

  2. Set log4cxx as startup project.

  3. Open project log4cxx's properties window, add other 3 projects as references, in here:
      properties -> common properties -> framework and references .
  4. Hit F7, if you see error c2252, this is because LOG4CXX_LIST_DEF define error, go to its definition and change it to

#define LOG4CXX_LIST_DEF(N, T) typedef std::vector<T> N

like this,

old:

#define LOG4CXX_LIST_DEF(N, T) \
template class LOG4CXX_EXPORT std::allocator<T>; \
template class LOG4CXX_EXPORT std::vector<T>; \
typedef std::vector<T> N

new:

#define LOG4CXX_LIST_DEF(N, T) typedef std::vector<T> N
  1. and u will meet another err about insert_iterator, simply add #include< iterator> to relative file

  2. Done! enjoy your log4cxx!

濫情▎り 2024-12-27 09:06:10

要使用 Visual Studio 2015 在 Windows 7 64 位上构建 log4cxx,除了 Scott 的回答之外,我还必须执行一些步骤,并进行一些说明。

  1. 此处下载最新的 log4cxx (apache 0.10.0) ZIP 包。
  2. 此处下载 apr 和 apr-util ZIP 包。
  3. 将 log4cxx、apr 和 apr-util 提取到同一目录。
  4. 从官方说明和seveves的回答来看:
    将 apr_VERSION 和 apr-util_VERSION 文件夹重命名为 apr 和 apr-util,生成一个包含三个文件夹的目录:apache-log4cxx-0.10.0、apr 和 apr-util
  5. 从 Visual Studio 命令行,cd 到 log4cxx 目录并执行“配置”。如果您尝试在下一步中使用它,则这在 git bash shell 中不起作用。
  6. 下一个脚本需要 sed,因此您有一些选择:
    • 按照其他答案中的说明手动编辑文件。
      • 切换到 apr-util/include 目录并在您选择的文本编辑器中打开 apu.hw。找到#define APU_HAVE_APR_ICONV 条目,将其设置为 0 并保存文件。从同一目录打开 apr_ldap.hw 并找到条目 #define APR_HAS_LDAP,将其设置为 0 并保存文件。
    • 从 GNUWin32 安装 sed 并将其添加到您的 PATH,然后通过 Windows 命令提示符从 log4cxx 目录运行“configure-aprutil”。
    • 通过在 Git Bash 提示符下从 log4cxx 目录运行“configure-aprutil”来使用 Windows git 安装附带的 sed。
  7. 打开 Visual Studio 2015。从项目目录中打开项目 log4cxx.dsw。让 Visual Studio 对其进行转换。
  8. 将 log4cxx 设置为启动项目,并检查其他 3 个项目是否显示为依赖项(右键单击 -> 构建依赖项 -> 项目依赖项)
  9. 现在,其中三个项目显示为“(Visual Studio 2010) ”在他们旁边。由于 stdio 的更改,这导致了稍后的链接错误:

    4>apr-1.lib(start.obj):错误 LNK2001:无法解析的外部符号 __imp__wenviron
    4>apr-1.lib(start.obj) : 错误 LNK2001: 无法解析的外部符号 __imp__environ
    4>apr-1.lib(filedup.obj) : 错误 LNK2019: 函数 apr_file_dup2 中引用了无法解析的外部符号 __imp___iob_func

    通过转到每个项目的“属性”并将所有配置的“平台工具集”更改为 Visual Studio 2015 来更改此设置。

  10. 该解决方案现已配置为 32 位。转到“构建”>配置管理器。将平台更改为 x64。其中三个项目将发生变化,但 log4cxx 仍然显示 Win32。单击该按钮并转到“新建...添加 x64”并取消选中“创建新解决方案平台”。单击“确定”。确保所有 4 个项目都选中“构建”。
  11. 如果您现在构建,您将看到 c2252 模板错误。打开log4cxx.h
    • 将包含 "#if Defined(_MSC_VER) && !define(LOG4CXX_STATIC) && Defined(LOG4CXX)" 的行更改为 "#if Defined(_MSC_VER) &第 1700 章定义(LOG4CXX)”
    • 将包含 "#elif Defined(_MSC_VER) && !define(LOG4CXX_STATIC)" 的行更改为 "#elif Defined(_MSC_VER) && _MSC_VER < 1700 & ;& !定义(LOG4CXX_STATIC)"
  12. 下一个错误将与 stringhelper.cpp 中的 insert_iterator 相关。将 #include 添加到该文件。
  13. 然后出现链接错误:

    apr-1.lib(rand.obj):错误 LNK2019:无法解析的外部符号 __imp__UuidCreate

    要解决此问题,请转到 log4cxx 属性 >链接器>输入并添加 rpcrt4.lib

  14. 现在应该构建解决方案,并且该库将链接到您的 64 位应用程序。如果您只编辑一个,请重复调试/发布配置。

  15. (可选)该解决方案不会将常见的“d”后缀添加到调试库。要添加它,请打开调试配置的属性。转到链接器>一般>输出文件并重置为默认值。转到链接器>高级>导入库并重置为默认值。对发布配置也执行此操作,以便它们将构建到相应的目录。仅对于调试配置,转到常规,然后在目标名称末尾添加“d”。

To build log4cxx on Windows 7 64-bit with Visual Studio 2015, I had to do a few steps in addition to Scott's answer, and have some clarifications.

  1. Download the latest log4cxx (apache 0.10.0) ZIP package from here.
  2. Download apr and apr-util ZIP packages from here.
  3. Extract log4cxx, apr, and apr-util to the same directory.
  4. From the official instructions and seveves's answer:
    Rename the apr_VERSION and apr-util_VERSION folder to apr and apr-util resulting in a directory with three folder: apache-log4cxx-0.10.0, apr and apr-util
  5. From a Visual Studio command line, cd to the log4cxx directory and execute "configure". This will not work from a git bash shell in case you are trying to use that for the next step.
  6. The next script requires sed, so you have some options:
    • Edit the files manually as described in the other answers.
      • Change to apr-util/include directory and open apu.hw in a texteditor of your choice. Find the entry #define APU_HAVE_APR_ICONV, set it to 0 and save the file. Open apr_ldap.hw from the same directory and find the entry #define APR_HAS_LDAP, set it to 0 and save the file, too.
    • Install sed from GNUWin32 and add it to your PATH, then run "configure-aprutil" from the log4cxx directory from a Windows command prompt.
    • Use the sed that comes with a Windows git installation by running "configure-aprutil" from the log4cxx directory from a Git Bash prompt.
  7. Open Visual Studio 2015. Open the project log4cxx.dsw from the projects directory. Let Visual Studio convert it.
  8. Set log4cxx as the startup project and check that the other 3 projects show up as dependencies (Right click -> Build Dependencies -> Project Dependencies)
  9. Now I had three of the projects showing up with "(Visual Studio 2010)" next to them. This caused a link error later due to changes in stdio:

    4>apr-1.lib(start.obj) : error LNK2001: unresolved external symbol __imp__wenviron
    4>apr-1.lib(start.obj) : error LNK2001: unresolved external symbol __imp__environ
    4>apr-1.lib(filedup.obj) : error LNK2019: unresolved external symbol __imp___iob_func referenced in function apr_file_dup2

    Change this by going to the Properties for each project and changing the "Platform Toolset" for all configurations to Visual Studio 2015.

  10. The solution is now configured for 32-bit. Go to Build > Configuration Manager. Change the platform to x64. Three of the projects will change but log4cxx still says Win32. Click on that and go to New... Add x64 and uncheck "Create new solution platform". Click OK. Make sure "Build" is checked for all 4 projects.
  11. If you build now, you will see the c2252 template errors. Open log4cxx.h
    • Change line containing "#if defined(_MSC_VER) && !defined(LOG4CXX_STATIC) && defined(LOG4CXX)" to "#if defined(_MSC_VER) && _MSC_VER < 1700 && !defined(LOG4CXX_STATIC) && defined(LOG4CXX)".
    • Change line containing "#elif defined(_MSC_VER) && !defined(LOG4CXX_STATIC)" to "#elif defined(_MSC_VER) && _MSC_VER < 1700 && !defined(LOG4CXX_STATIC)".
  12. The next error will be about insert_iterator in stringhelper.cpp. Add #include <iterator> to that file.
  13. Then there is a link error:

    apr-1.lib(rand.obj) : error LNK2019: unresolved external symbol __imp__UuidCreate

    To fix this, go to log4cxx Properties > Linker > Input and add rpcrt4.lib

  14. Now the solution should build and and the library will link to your 64-bit application. Repeat for Debug/Release configurations if you were only editing one.

  15. (Optional) The solution doesn't add the common "d" suffix to the debug library. To add it, open up the Properties for the Debug configuration. Go to Linker > General > Output file and reset to default. Go to Linker > Advanced > Import Library and reset to default. Do this for the Release configuration as well so that they will build to corresponding directories. For only the Debug configuration, go to General, and add a "d" at the end of the Target Name.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文