可选地在C ++中包括头文件 [英] Include header files optionally in C++

查看:83
本文介绍了可选地在C ++中包括头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++代码,该代码需要在某些服务器而不是其他服务器中包含某个库。我使用bjam构建代码。

I have a C++ code which needs to include a certain library in some servers and not in other servers. I build my code using bjam.

代码示例:

if server in server_list:
   include <header-file.h>
   int function();
else:
   int function();

在使用bjam构建期间:

And during build using bjam:

if server in server_list:
    -llibrary
else:
   ...


推荐答案

头文件包含是编译时活动,而不是运行时。因此,如果条件相同,就无法使用

Header file inclusion is a compile time activity not run time. So you can't use if conditions for the same

使用#ifdefs

#define SERVER_IN_LIST

#ifdef SERVER_IN_LIST
    #include<...>
#endif

这篇关于可选地在C ++中包括头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆