我在 CMake 中有一个不断发展的项目。是时候链接到一个库了,此时它只存在于 Windows 中,Linux 功能将不得不等待。我正在尝试按照对 this question 的回答中的建议使用预处理器指令来执行此操作:
// MyLibHeader.hpp
#ifdef WIN32
#include <windows.h>
#define ProcHandle HINSTANCE
#define LoadLib LoadLibraryA
#define LoadSym GetProcAddress
#else
// ... I'll fill these in with dlopen etc. when necessary
这是我必须放入我的代码中的第一个特定于平台的包含,而且它似乎不止于此。这会产生此错误:
C:\Program Files (x86)\Microsoft Visual Studio 8\VC\include\intrin.h(944) : error C2733: second C linkage of overloaded function '_interlockedbittestandset' not allowed
该错误重复四次,intrin.h 中两次,winnt.h 中两次。所以这是我的问题。我是否需要采取其他包含或预处理器步骤才能使其在 Windows 中运行(到目前为止,它一直是一个基本的控制台应用程序),CMake 中是否有一些我可以利用的东西来简化它。
最佳答案
根据我在一些帮助和谷歌上搜集到的信息,一种解决方案确实是在 initrin.h
中注释掉 _interlockedbittestandset
的重复定义
这可能已在更高版本的 Visual Studio 中得到修复。
关于c++ - Windows 库包含在 CMake 项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9688145/