Conditional #include in C

允我心安 提交于 2019-12-03 16:27:01

You could have a team.h file that defines any macros for Team A and doesn't define them for Team B or defines different values and each team would have their own copy of team.h .

Each team member could also pass that value to the compiler via the -D option a macro (at least the Linux compilers support that). I would recommend that if you do that you pass TEAM_A or TEAM_B in order to give you more flexibility in the future and not have to pass more macros.

The solution you suggested is usually the one being used, and it is done pretty often. You can also pass the macro in the makefile / project file.

Also note, that Tools.h is a header file, and will always be compiled as part of another file.

I fooled myself. As stated above, there is nothing wrong with the code. I missinterpreted the errormessage of my IDE.

As to stay with the example, I had also the Tools.c and the compilation of that source failed (naturally), because I hadn't XML.h in my project. Removing the source from the projekt and just link against the precompiled Tools works fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!