PDA

View Full Version : Problems importing logging-cpp library into a simple Qt program



scrat75
20th July 2010, 14:30
Hi all,

googling around looking for a C++ logging framework I found this library (see http://www.drdobbs.com/cpp/225700666 and http://logging-cpp.sourceforge.net/).
I downloaded the source code (see http://i.cmpnet.com/ddj/images/article/2010/code/logging-cpp.zip), then I extracted it in a directory.
In the subdir tst there are some application examples, there I decided to make a simple Qt application using the logging library (released as a bunch of header files) to see if the integration with Qt library was possible.
Here is my code, constructed from an existing example in the tst directory.



#include <QApplication>

//#define LOGGING_DISABLE
#include "logging/logging.h"
using namespace ::logging;

// logging levels can be disabled at compile time
//LOGGING_DISABLE_LEVEL(::logging::Error);
//LOGGING_DISABLE_LEVEL(::logging::Trace);
//LOGGING_DISABLE_LEVEL(::logging::Warning);
//LOGGING_DISABLE_LEVEL(::logging::Info);

int main(int argc, char **argv)
{
QApplication app(argc, argv);

log::emit() << "Hello World! with the logging framework"
<< log::endl << log::endl;
log::emit() << "Print 15 in hexadecimal "
<< log::hex << 15 << log::endl;
log::emit() << "Print 15 in decimal "
<< log::dec << 15 << log::endl;
log::emit() << "Print 15 in octal "
<< log::oct << 15 << log::endl;
log::emit() << "Print 15 in binary with a tab"
<< log::bin << log::tab << 15
<< log::endl << log::endl;

log::emit< Error>() << "Logging an Error"
<< log::endl;
log::emit< Trace>() << "Logging a Trace"
<< log::endl;
log::emit< Warning>() << "Logging a Warning"
<< log::endl;
log::emit< Info>() << "Logging an Info"
<< log::endl;

return app.exec();
}


Following the qmake project file I used to build my example (tst.pro):



TEMPLATE = app
TARGET = qt
DEPENDPATH += .
INCLUDEPATH += ../include
QMAKE_CXXFLAGS += -std=c++0x
QMAKE_CFLAGS += -std=c++0x

# Input

LIBS += -L ../include
SOURCES += qt.cpp


After creation of the Makefile (with command qmake tst.pro), I ran the make cmd, but I obtained following error:



g++ -c -pipe -std=c++0x -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I../include -I. -o qt.o qt.cpp
In file included from ../include/logging/OutputStream.h:43,
from ../include/logging/logging.h:44,
from qt.cpp:4:
../include/logging/Logger.h:199: error: expected unqualified-id before ‘)’ token
../include/logging/Logger.h:200: error: expected primary-expression before ‘return’
../include/logging/Logger.h:200: error: expected ‘}’ before ‘return’
../include/logging/Logger.h:204: error: too few template-parameter-lists
../include/logging/Logger.h:209: error: expected declaration before ‘}’ token
make: *** [qt.o] Error 1


I discovered that omitting the include instruction
#include <QApplication>[7CODE] (at line #1), commenting line #15 and using instruction [CODE]return 0 instead of
return app.exec(); al line #38 I can compile without errors the application.

Could be the problem arising because of some options used in the Makefile build by qmake?
Or in some missing options whose absence generates the reported errors?

Thanks in advance for the help you can give me.