C++ 禁用特定的C++;在另一个系统上构建时的行和#包括
我在我的项目中使用Google glog日志系统。具体来说,我在代码中的不同位置使用了以下类型的语句:C++ 禁用特定的C++;在另一个系统上构建时的行和#包括,c++,eclipse,gcc,build,makefile,C++,Eclipse,Gcc,Build,Makefile,我在我的项目中使用Google glog日志系统。具体来说,我在代码中的不同位置使用了以下类型的语句: #include <glog/logging.h> CHECK_EQ(foo,bar) << "Generic error message"; LOG(ERROR) << "Generic error message"; LOG(FATAL) << "Generic error message"; 注意:目前,我只是对CHECK_EQ调用进行了
#include <glog/logging.h>
CHECK_EQ(foo,bar) << "Generic error message";
LOG(ERROR) << "Generic error message";
LOG(FATAL) << "Generic error message";
注意:目前,我只是对
CHECK_EQ
调用进行了注释,认为一旦我找到了解决LOG
调用相关问题的方法,我应该能够轻松地将解决方案扩展到CHECK_EQ
调用。对于您的编译问题
message我接受了Jarod42的答案,但我想在这里添加我自己的答案,我最终可能会使用它。我认为Jarod42可能更优雅、更好,但我的黑客解决方案很容易实现
我发现,与其在编译步骤中尝试向CXXFLAGS添加一个变量,然后定义该变量来表示是否使用glog系统,不如简单地在Eclipse中基于现有的版本配置创建另一个构建配置。在这个新的配置中,调用它>代码> RelaseS.NoGug ,然后我可以转到属性> C/C++ + Buffe>设置> GCC C++编译器>预处理器,并将<代码> NoGracg < /Cord>作为“定义符号”。这样,内置release
不会将NOGLOG
添加到compile语句中,但内置release\u NOGLOG
会
然后,我可以简单地使用以下宏定义:
#ifdef NOGLOG
#define MYLOG(i,m) std::cerr << #i << ": " << m
#define MYCHECK_EQ(i,j,m) CHECK_EQ(i,j) << m
#else
#define MYLOG(i,m) LOG(i) << m
#define MYCHECK_EQ(i,j,m) std::cerr << #i << " != " << #j << ": " << m
#endif
#ifdef NOGLOG
#定义MYLOG(i,m)std::cerr vee一个非常简单的问题。您是否查看了项目的属性“C++常规->路径和符号”#符号选项卡?Eclipse CDT工具链还提供了多种其他方法。另外:/usr/include/bits/errno.h-编译环境真糟糕。@g-makulik谢谢,我将对此进行研究。我从来没有弄乱过任何EclipseCDT工具链。所以这对我来说是全新的。@DieterLücking我想这应该归功于glog库。谢谢这个有用的解决方案。问题,尽管。。。为什么消息为true,is不是无效的,但作为操作符,我建议每次删除m
参数(因此
In file included from /usr/include/errno.h:36,
from /usr/local/include/glog/logging.h:39,
from ../globals.h:23,
from ../COMPASS.h:11,
from ../COMPASS.cpp:13:
/usr/include/bits/errno.h: In function 'int* __errno_location()':
/usr/include/bits/errno.h:43: error: expected primary-expression before ',' token
// mystream.h
// class MyStreamImpl; // forward declaration for pimpl idiom if necessary
class MyStream
{
public:
MyStream(int level);
~MyStream();
MyStream& operator << (const char*);
MyStream& operator << (int);
// some other needed base type.
private:
int level;
// std::unique_ptr<MyStreamImpl> m_impl; // for pimpl idiom if necessary
};
MyStream MYLOG(int level) { return MyStream(level); }
// mylog.cpp
#ifdef NOGLOG
#include <iostream>
// implementation of all methods without glog
MyStream& MyStream::operator << (const char* message)
{
std::cerr << message;
return *this;
}
// other forwards to std::cerr
#else // NOGLOG
#include <glog/logging.h>
// implementation of all methods with glog
MyStream& MyStream::operator << (const char* message)
{
Log(level) << message;
return *this;
}
// other forwards to LOG()
#endif
#ifdef NOGLOG
#define MYLOG(i,m) std::cerr << #i << ": " << m
#define MYCHECK_EQ(i,j,m) CHECK_EQ(i,j) << m
#else
#define MYLOG(i,m) LOG(i) << m
#define MYCHECK_EQ(i,j,m) std::cerr << #i << " != " << #j << ": " << m
#endif