简体   繁体   English

Eclipse CDT条件编译?

[英]Eclipse CDT conditional compilation?

I have a line of code that Eclipse CDT (Oxygen) code fails to recognise. 我有一行Eclipse CDT(Oxygen)代码无法识别的代码。 I'm pretty sure the code is perfectly fine. 我很确定代码完全正确。 It compiles OK but I still like project without red squiggles on them. 它可以编译,但是我仍然喜欢没有红色花键的项目。

How can I tell Eclipse ignore this line? 如何告诉Eclipse忽略这一行? I imagine I would enclose it in conditional compilation directives that only affect code checking but not normal compilation. 我想我会将其包含在仅影响代码检查但不影响正常编译的条件编译指令中。 Something like this: 像这样:

#ifdef _ECLIPSE_CODE_CHECKER
    my_bad_code();
#endif

But I cannot find any such macro predefined by Eclipse. 但是我找不到Eclipse预定义的任何此类宏。

It would be even better to make the code checker simply accept this line. 最好使代码检查器简单地接受这一行。

Here's the smallish example: 这是个小例子:

#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/support/date_time.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

namespace logging = boost::log;
namespace expr = boost::log::expressions;
namespace bpt = boost::posix_time;


int main()
{
  logging::add_file_log(
   logging::keywords::file_name ="file.log",
   logging::keywords::format =
    (expr::stream << expr::format_date_time<bpt::ptime >("T:", "%H:%M:%S") << expr::smessage));    
}

Eclipse complains about add_file_log having invalid arguments. Eclipse抱怨add_file_log具有无效的参数。 Removing format_date_time makes the error go away. 删除format_date_time可使错误消失。

The macro you're looking for exists and is called __CDT_PARSER__ : 您要查找的宏存在并且称为__CDT_PARSER__

#ifdef __CDT_PARSER__
    my_bad_code();
#endif

As for Eclipse's code checker accepting the line, I would encourage you to file a CDT bug . 至于Eclipse的代码检查器接受这一行,我鼓励您提交CDT bug

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM