我一直在嘗試構建使用Poco :: Application類作爲其基礎的可執行文件,但編譯器提供了以下指向Poco代碼的錯誤。Linux上的Poco :: Logger的編譯錯誤 - 函數聲明被視爲宏
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
在這裏,我包括從我的主目錄最新版本波科(1.4.6p4),但我已經試過1.4.2p1-2.el6從CentOS的具有相同的結果6.5庫。在OS X上我沒有這個問題(我相信那裏的庫版本是1.4.2)。
如果我看第152行Poco/Logger.h中的內容,第一個錯誤指向的地方,它似乎是一個函數聲明,而不是錯誤狀態。
//
// 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)
那麼,爲什麼我的編譯器將此函數聲明視爲對宏的引用呢?
作爲一個方面說明,在剛剛發佈的構建過程中,出現了一個奇怪的錯誤。也許這些都是相關的。我試着在一個內聯函數使用FMOD功能從tgmath.h和編譯器給了這個錯誤六次一行代碼:
/.../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
這是觸發該錯誤的頭文件的代碼:
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;
}
包含頭文件tgmath.h,並且在OS X上編譯的代碼沒有問題。我不明白錯誤中的void *指向哪裏。
我一直在CentOS 6.5上使用GCC 4.4.7,在Ubuntu 12.04上使用GCC 4.4.6.3-1ubuntu5。