building log4cxx in vs 2010 c++

ぐ巨炮叔叔 提交于 2019-11-29 01:53:32

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

Julien

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.

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!

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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!