在预处理器指令中包含静态库

Include static library within a preprocessor directive

本文关键字:包含 静态 指令 预处理 处理器      更新时间:2023-10-16

我使用的是Visual Studio 2012。

我多次使用像 这样的预处理器指令
#ifdef something 
      #include<some_header.h>
#else
      #include<other_header.h>
#endif

我想知道是否有可能以类似的方式链接静态库:

#ifdef something 
      // use some_library.lib
#else
      // use other_library.lib
#endif

这个问题来自于我之前的问题:我有两个静态库。自由,lib2。Lib(不是它们的代码),没有名称空间,具有相同的函数原型,但具有不同的实现。

如果您正在使用MSVC,您可以使用

#ifdef something 
      #pragma comment(lib,"xxx.lib")
#else
      #pragma comment(lib,"zzz.lib")
#endif