在Ubuntu 20.04系统中编译netanim-3.107,遇到如下错误:
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DNS3_LOG_ENABLE -DQT_NO_DEBUG -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -Iqtpropertybrowser/src -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtPrintSupport -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o fatal-impl.o fatal-impl.cpp
In file included from fatal-impl.cpp:21:
fatal-impl.cpp: In destructor ‘ns3::FatalImpl::{anonymous}::destructor::~destructor()’:
log.h:323:44: error: ambiguous overload for ‘operator<<’ (operand types are ‘ns3::ParameterLogger’ and ‘ns3::FatalImpl::{anonymous}::destructor*’)
323 | ns3::ParameterLogger (std::clog) << parameters;
fatal-impl.cpp:71:5: note: in expansion of macro ‘NS_LOG_FUNCTION’
71 | NS_LOG_FUNCTION (this);
| ^~~~~~~~~~~~~~~
log.h:412:20: note: candidate: ‘ns3::ParameterLogger& ns3::ParameterLogger::operator<<(T) [with T = ns3::FatalImpl::{anonymous}::destructor*]’
412 | ParameterLogger& operator<< (T param)
但是编译netanim-3.108却没有问题。打开3.108中的log.h查看NS_LOG_FUNCTION的定义,果然有所不同。netanim-3.107该宏定义如下:
#define NS_LOG_FUNCTION(parameters)
do
{
if (g_log.IsEnabled (ns3::LOG_FUNCTION))
{
NS_LOG_APPEND_TIME_PREFIX;
NS_LOG_APPEND_NODE_PREFIX;
NS_LOG_APPEND_CONTEXT;
std::clog << g_log.Name () << “:”
<< FUNCTION << “(”;
ns3::ParameterLogger (std::clog) << parameters ;
std::clog << “)” << std::endl;
}
}
while (false)
而在netanim-3.108中该方法定义如下:
#define NS_LOG_FUNCTION(parameters)
do
{
if (g_log.IsEnabled (ns3::LOG_FUNCTION))
{
NS_LOG_APPEND_TIME_PREFIX;
NS_LOG_APPEND_NODE_PREFIX;
NS_LOG_APPEND_CONTEXT;
std::clog << g_log.Name () << “:”
<< FUNCTION << “(”;
ns3::ParameterLogger (std::clog).***operator<<(parameters);***
std::clog << “)” << std::endl;
}
}
while (false)
见上面两段代码加粗斜体的不同,修改后就可以编译通过。