Click to See Complete Forum and Search --> : Urgent help needed in using log4cpp


The Saint
October 13th, 2005, 07:16 AM
:thumb:
Hi,
I have downloaded log4cpp and am facing two problems.
First Problem
I built the log4cpp in VC 7.0 as MDd in debug version. I put log4cppD.dll & log4cppD.lib in my debug folder. When I try to link it to my static library, it is giving the following linking errors (614 in total). My atatic library is also built as MDd in debug verison.


log4cppD.lib(log4cppD.dll) : warning LNK4006: "public: int __thiscall log4cpp::CategoryStream::width(int)" (?width@CategoryStream@log4cpp@@QAEHH@Z) already defined in log4cppD.lib(log4cppD.dll); second definition ignored
....
....
log4cppD.lib(log4cppD.dll) : warning LNK4006: "public: static void __cdecl log4cpp::Category::setRootPriority(int)" (?setRootPriority@Category@log4cpp@@SAXH@Z) already defined in log4cppD.lib(log4cppD.dll); second definition ignored
....
....
log4cppD.lib(log4cppD.dll) : warning LNK4006: "__declspec(dllimport) public: virtual void __thiscall log4cpp::NTEventLogAppender::setLayout(class log4cpp::Layout *)" (__imp_?setLayout@NTEventLogAppender@log4cpp@@UAEXPAVLayout@2@@Z) already defined in log4cppD.lib(log4cppD.dll); second definition ignored
....
...
log4cppD.lib(log4cppD.dll) : warning LNK4006: "__declspec(dllimport) protected: void __thiscall log4cpp::NTEventLogAppender::regSetDword(struct HKEY__ *,char *,unsigned long)" (__imp_?regSetDword@NTEventLogAppender@log4cpp@@IAEXPAUHKEY__@@PADK@Z) already defined in log4cppD.lib(log4cppD.dll); second definition ignored
.......
....
log4cppD.lib(log4cppD.dll) : warning LNK4006: "public: __thiscall log4cpp::AbortAppender::AbortAppender(class log4cpp::AbortAppender const &)" (??0AbortAppender@log4cpp@@QAE@ABV01@@Z) already defined in log4cppD.lib(log4cppD.dll); second definition ignored
...
log4cppD.lib(log4cppD.dll) : warning LNK4006: __IMPORT_DESCRIPTOR_log4cppD already defined in log4cppD.lib(log4cppD.dll); second definition ignored


Can anyone please tell me why am I getting these linking errors and how to resolve the same?


Second Problem
When I try to use the log4cpp in VC 6.0, I get the errors

d:\log4cpp-0.3.5rc1\include\log4cpp\priority.hh(65) : error C2258: illegal pure syntax, must be '= 0'
d:\log4cpp-0.3.5rc1\include\log4cpp\priority.hh(65) : error C2252: 'MESSAGE_SIZE' : pure specifier can only be specified for functions
d:\log4cpp-0.3.5rc1\include\log4cpp\threading\msthreads.hh(160) : fatal error C1506: unrecoverable block scoping error


Please help me on this too.

Also please help in using log4cpp with MFC dialog based applications. I am not certain of the type of runtime library i need to set.

Rigel
October 13th, 2005, 09:29 AM
Here's what you can do in Visual Studio 6.0.

Go to the "build" tab at the bottom of the editor where you see the errors occur. To figure out what was wrong highlight one of errors in bold. Press "F1". You'll find a definition of the error.


4cpp\priority.hh(65) : error C2258: illegal pure syntax, must be '= 0'
4cpp\priority.hh(65) : error C2252: 'MESSAGE_SIZE' : pure

Bob Davis
October 13th, 2005, 11:36 AM
With regard to your first problem, you didn't show any linker errors. Those are all warnings, so it's possible that your code could have built just fine.

The Saint
October 13th, 2005, 11:42 AM
Here's what you can do in Visual Studio 6.0.

Go to the "build" tab at the bottom of the editor where you see the errors occur. To figure out what was wrong highlight one of errors in bold. Press "F1". You'll find a definition of the error.

Thank you. I am aware of that. But what I want to know is, how safe would it be to comment this and build the lib.

With regard to your first problem, you didn't show any linker errors. Those are all warnings, so it's possible that your code could have built just fine.


They are warnings as long as I do not call any function from the library. nce I try to get an instance of category or configure the SimpleConfigurator, then I get compilation errors.

Rigel
October 13th, 2005, 11:53 AM
Thank you. I am aware of that. But what I want to know is, how safe would it be to comment this and build the lib.


Why not just fix the problem? It's a very simple fix.
Why would you want to comment out something that is potentially important to the library? I wouldn't comment anything out unless I knew full well commenting it out would have any drastic consequences.

The Saint
October 13th, 2005, 12:27 PM
Why not just fix the problem? It's a very simple fix.
Why would you want to comment out something that is potentially important to the library? I wouldn't comment anything out unless I knew full well commenting it out would have any drastic consequences.

Hi mate,
Well I meant that I am aware of how to get to the definiton of the error. My query was on how to solve the error which does not occur in VC7.

Wombat
October 13th, 2005, 06:56 PM
Hi Saint,

How about u zip up the code (together with the lib and dll) and post it up here? That would be easier for ppl to try it out and solve ur problems, instead of guessing the causes of the errors.

The Saint
October 13th, 2005, 11:35 PM
Hi,
I am attaching the files for your reference. The Log4CPP.zip contains the source code that I am using to build the log4cpp dll & library.

Mailslots.zip contains my static library. In the file CommonDefs.h under Mailslots, if you comment out


log4cpp::SimpleConfigurator::configure("..\\log\\log4cpp.init");
log4cpp::Category& g_Log = log4cpp::Category::getInstance("Mailslots");


then it will generate the 600+ linker warnings. When these lines are added it generates compilation errors.


Please let me know how to solve this as I am on a tight schedule to finish this. :blush:

Wombat
October 14th, 2005, 01:02 AM
Hi Saint,

It would be better if you provide the actual environment under MS Visual Studio 6. The only .dsw file you provide is msvc6.dsw, but majority of the projects (*.dsp) under it cannot be found. Under the mailslot folder is only the solution file which cannot be openned under vs6.

The Saint
October 14th, 2005, 01:11 AM
Hi Saint,

It would be better if you provide the actual environment under MS Visual Studio 6. The only .dsw file you provide is msvc6.dsw, but majority of the projects (*.dsp) under it cannot be found. Under the mailslot folder is only the solution file which cannot be openned under vs6.

Hi Wombat,
The log4cpp is the latest version. I uploaded only the relevant files due to size constraint.


My project is in VC7 and hence the mailsot solution too is in VC7.

Paul McKenzie
October 14th, 2005, 02:13 AM
Hi Wombat,
The log4cpp is the latest version. I uploaded only the relevant files due to size constraint.But are these *all* the files needed to reproduce the compiler error?

No one, unless they have a lot of time, will do a search on the internet to find "log4cpp", download a library, install a library, set up an environment, etc., etc. to reproduce a compiler error. You need to provide all the information and preferably all the files that reproduce the error.

Regards,

Paul McKenzie

The Saint
October 14th, 2005, 04:03 AM
Hi Paul,
True that no one would do a search on the internet to find "log4cpp", download a library, install a library, set up an environment, etc., etc. to reproduce a compiler error.

I could not upload the library as it is more than the allowed 250 KB upload limit here.

So the next best thing I could do was give the source which can be built. There is a .dsp file which can be attached to a .dsw file in VC6 and a .sln file for VC7.

The other files/.dsp that is being referred here are not for log4cpp library. They are samples that come along with the log4cpp workspace.

This is the best that I could give. If you feel that I could provide more information in any other way do guide me.

Wombat
October 14th, 2005, 04:19 AM
Hi Saint,

I tried to compile your log4cpp project under vs6 and manage to get the same errors as yours. And the culprit is the following line in priority.hh:


class LOG4CPP_EXPORT Priority {
public:
static const int MESSAGE_SIZE=8;

///// Some other declarations //////
};



You can't initialize variables inside a class in this manner. The compiler mistaken it as a pure virtual function declaration, and thus generates the errors.

To solve, take out the initialization portion:

static const int MESSAGE_SIZE;


If you need to initialize it to a value other than 0, do it at file scope inside priority.cpp :


#include "PortabilityImpl.hh"
#include <log4cpp/Priority.hh>
#include <cstdlib>

const int log4cpp::Priority::MESSAGE_SIZE=8;


It should be able to compile successfully.

The Saint
October 14th, 2005, 04:25 AM
Thanks you very much wombat. I wonder how I missed that. So stupid of me.

Actually I have been engrossed with the linking issue that when my mate came to me with this error I just did not realize it.

Thank you again. Can you please help me on the other problem?

Paul McKenzie
October 14th, 2005, 04:57 AM
You can't initialize variables inside a class in this manner. The compiler mistaken it as a pure virtual function declaration, and thus generates the errors.To be more clear, you can't do this with Visual C++ 6.0, but it is perfectly valid C++ syntax.

Saint (and Wombat), the issue is that Visual C++ 6.0 does not support all of the modern C++ syntax. If you get a third-party library, make sure it clearly states that it was compiled using Visual C++ 6.0 before wasting time getting it to work on VC 6.0. If not, you will more than likely get problems such as this, since the original coders of the library were using more up-to-date ANSI compliant C++ compilers when developing the library.

Regards,

Paul McKenzie

The Saint
October 14th, 2005, 05:58 AM
Hi Paul,
Shall do so in the future. Actaully when I reomved the initialization from the class scope everything worked fine. I also think that the code does not account completely for multiple inclusions.

I am not sure whether #ifndef is better or #pragma once is better.

Wombat
October 14th, 2005, 07:38 AM
To be more clear, you can't do this with Visual C++ 6.0, but it is perfectly valid C++ syntax.


Thanks for highlighting that. :thumb:

The Saint
October 14th, 2005, 11:19 AM
somebody please help me on the first problem.

Paul McKenzie
October 14th, 2005, 11:31 AM
The warning states that you have functions implemented more than once. Your job is to look at the function(s) the linker is complaining about and see where they are defined and implemented in your project.

Are theses implemented in two (or more) source modules?

Regards,

Paul McKenzie

The Saint
October 15th, 2005, 05:09 AM
The warning states that you have functions implemented more than once. Your job is to look at the function(s) the linker is complaining about and see where they are defined and implemented in your project.

Are theses implemented in two (or more) source modules?

Regards,

Paul McKenzie


Hi Paul,
I plan to do so. They are implemented in one source only.

sgris
October 15th, 2005, 07:15 AM
The Saint,
I don't have much time to follow all of the opsts in your thread ...
but personally i am sure limiting the resource used as small as possible is always highly recommended, although that would bring about performance issues...that is why the target should be at how to set up an equillibrium equation to gain most benifits in a certain application under a given situation..

Paul McKenzie
October 15th, 2005, 07:26 AM
If it isn't implemeted in two or more source modules, then you are linking in two or more object modules that contain the implementations. If you have an a.obj or a.lib, and you have a b.obj or b.lib, and for some reason a function is found in two or more of these libraries, the linker will warn you.

Therefore a search for a function in the source code being implemented more than once may not find what you're looking for. Look at your project, look what is being linked. The linker *is* finding two implementations in the object code/libraries being linked.

Regards,

Paul McKenzie