Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
683 views
in Technique[技术] by (71.8m points)

visual c++ - building log4cxx in vs 2010 c++

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:...projectsapr-utilxmlexpatlibxml.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:UsersxDocumentsVisual Studio 2010Projectsaprapr.dsp : error  : Project upgrade failed.

C:UsersxDocumentsVisual Studio 2010Projectsapr-utilxmlexpatlibxml.dsp : error  : Project upgrade failed.

C:UsersxDocumentsVisual Studio 2010Projectsapr-utilaprutil.dsp : error  : Project upgrade failed.

C:UsersxDocumentsVisual Studio 2010Projectsapache-log4cxx-0.10.0projectslog4cxx.dsp : error  : Project upgrade failed.

Thanks

The files are in the correct path.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...