Pnog is not Pong
Pnog is not Pong

Reputation: 187

Compiler errors with Poco::Logger on Linux - function declaration treated as macro

I've been trying to build executable that uses Poco::Application class as its basis, but compiler is giving following errors pointing to Poco code.

In file included from /home/mie/Poco/poco-1.4.6p4/Util/include/Poco/Util/Application.h:48:0,
                 from /home/mie/myproject/src/main.cpp:15:
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:152:59: error: macro "log" passed 3 arguments, but takes just 1
In file included from /home/mie/Poco/poco-1.4.6p4/Util/include/Poco/Util/Application.h:48:0,
                 from /home/mie/myproject/src/main.cpp:15:
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:427:58: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:428:86: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:601:72: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:610:100: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:621:30: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:627:42: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:633:33: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:639:45: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:645:30: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:651:42: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:657:32: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:663:44: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:669:31: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:675:43: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:681:36: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:687:48: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:693:30: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:699:42: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:705:30: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:711:42: error: macro "log" passed 4 arguments, but takes just 1
In file included from /home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:44:0,
                 from /home/mie/Poco/poco-1.4.6p4/Util/include/Poco/Util/Application.h:48,
                 from /home/mie/myproject/src/main.cpp:15:
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Channel.h:75:15: error: expected unqualified-id before ‘__extension__’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Channel.h:75:15: error: expected ‘)’ before ‘__extension__’
In file included from /home/mie/Poco/poco-1.4.6p4/Util/include/Poco/Util/Application.h:48:0,
                 from /home/mie/myproject/src/main.cpp:15:
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:145:7: error: expected unqualified-id before ‘__extension__’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:145:7: error: expected ‘)’ before ‘__extension__’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:149:7: error: expected unqualified-id before ‘__extension__’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:149:7: error: expected ‘)’ before ‘__extension__’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:152:7: error: variable or field ‘log’ declared void
In file included from /home/mie/Poco/poco-1.4.6p4/Util/include/Poco/Util/Application.h:48:0,
                 from /home/mie/myproject/src/main.cpp:15:
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:427:7: error: variable or field ‘log’ declared void
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:428:7: error: variable or field ‘log’ declared void
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:601:21: error: variable or field ‘log’ declared void
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:601:21: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x [enabled by default]
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:603:2: error: expected primary-expression before ‘if’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:603:2: error: expected ‘}’ before ‘if’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:610:13: error: ‘Logger’ has not been declared
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:610:21: error: variable or field ‘log’ declared void
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:610:21: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x [enabled by default]
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:612:2: error: expected primary-expression before ‘if’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:612:2: error: expected ‘}’ before ‘if’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:616:1: error: expected declaration before ‘}’ token
make[2]: *** [CMakeFiles/app.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/app.dir/all] Error 2

Here I'm including latest version of Poco (1.4.6p4) from my home directory, but I've tried 1.4.2p1-2.el6 from CentOS 6.5 repositories with same result. On OS X I didn't have this problem (I believe the library version there was 1.4.2).

If I look what's in Poco/Logger.h on line 152, where the first error points to, it seems to be a function declaration rather than macro as the error states.

//
// Logger.h
//
// $Id: //poco/1.4/Foundation/include/Poco/Logger.h#5 $
//
// Library: Foundation
// Package: Logging
// Module:  Logger
//
// Definition of the Logger class.
... (comment continues)


#ifndef Foundation_Logger_INCLUDED
#define Foundation_Logger_INCLUDED


#include "Poco/Foundation.h"
#include "Poco/Channel.h"
#include "Poco/Message.h"
#include "Poco/Format.h"
#include <map>
#include <vector>
#include <cstddef>


namespace Poco {


class Exception;


class Foundation_API Logger: public Channel
        /// Logger is a special Channel that acts as the main
        /// entry point into the logging framework.
    ... (comment continues)
{
public:
    ... (other declarations)

    void log(const Exception& exc, const char* file, int line);     <= line 152
                /// Logs the given exception with priority PRIO_ERROR.  
                ///
                /// File must be a static string, such as the value of
                /// the __FILE__ macro. The string is not copied
                /// internally for performance reasons.

    ... (and so on)

So why is my compiler treating this function declaration as a reference to macro?

As a side note, there was a weird error earlier in the build process that I just commented out. Maybe these are related. I tried to use fmod function from tgmath.h in an inline function and compiler gave this error six times for one line of code:

/.../header.h:418: error: ”void*” is not a pointer-to-object type
/.../header.h:418: error: ”void*” is not a pointer-to-object type
/.../header.h:418: error: ”void*” is not a pointer-to-object type
/.../header.h:418: error: ”void*” is not a pointer-to-object type
/.../header.h:418: error: ”void*” is not a pointer-to-object type
/.../header.h:418: error: ”void*” is not a pointer-to-object type

And this is the code in a header file that triggered the error:

inline void ProgressCounter::createTimeString(
    std::string& timeString,
    const long long& elapsedTotalS)
{
    short elapsedH = (short)elapsedTotalS / 3600;
    //short elapsedS = 0;
    short elapsedS = fmod(elapsedTotalS, 60);           <= error here
    short elapsedM = 0;
    //short elapsedM = fmod(elapsedTotalS - elapsedS, 3600) / 60;
    char timeCString[10];
    snprintf(timeCString, 10, "%02u:%02u:%02u", elapsedH, elapsedM, elapsedS);

    timeString = timeCString;
}

The header tgmath.h is included and the code compiled without problems on OS X. I don't understand where the void* in the error refers to.

I've been using GCC 4.4.7 on CentOS 6.5 and GCC 4.4.6.3-1ubuntu5 on Ubuntu 12.04.

Upvotes: 0

Views: 632

Answers (2)

alexisdm
alexisdm

Reputation: 29896

<math.h> and <tgmath.h> define a lot of macros, including a log macro which conflicts with anything with the same name.

In C++ code, you should rather include <cmath> or <ctgmath> where the type-generic macros are replaced by C++ function overloads.

PS: at least for gcc, <ctgmath> seems to require C++11 support, so you'll have to add "-std=c++0x" or "-std=c++11" to the compilation options.

Upvotes: 1

Logicrat
Logicrat

Reputation: 4468

Try including your POCO libraries first and see if that helps. I had a problem just a few days ago in VS 2010 on Windows in which a lot of Windows APIs suddenly became undefined when I had #included the POCO libraries last. Moving them ahead of other #includes fixed the problem.

Having fixed it, I did not do deep analysis of exactly what item had caused the problem.

Upvotes: 0

Related Questions