0

我正在尝试构建 Mypintool 示例,该示例附带用于 x64 架构的引脚分配。我正在使用 pin3.0 (build 76991) 和 Visual Studio 2012。如果我没有包含windows.h. 但是,如果我window.h像这样包含(在单独的命名空间中):-

namespace WD {
    #include "Windows.h"
}

然后构建给出错误: -

C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(3486): error C2888: '_CONTEXT::<unnamed-tag>' : symbol cannot be defined within namespace 'WD'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(3488): error C2888: '_CONTEXT::<unnamed-tag>::<unnamed-tag>' : symbol cannot be defined within namespace 'WD'

此外,我能够构建windows.h包含没有任何问题的 win32 工具。此外,我比较了 win32 和 x64 的构建设置,但找不到任何差异。

任何帮助表示赞赏。

4

1 回答 1

1

我不清楚您是否有使用“Pin”的 Windows 应用程序或需要调用某些 Windows API 的“Pin”应用程序 - 或者在单个程序中大量使用两种 API 的混合。

尽管如此,Windows SDK 还是相当大的,并且(主要)被设计为与 C 一起使用,或者与与 C 兼容的 C++ 的子集一起使用,因此如果包装在命名空间中,则不能期望它可以使用。

因此,处理标头冲突的唯一有效方法是避免在同一个 cpp 文件中包含“pin”或“windows”标头。您需要将程序中调用 windows 的部分和调用“pin”的部分划分为单独的 cpp 文件。

创建一个桥接头文件,该文件定义仅使用 C++ 声明的类和函数。由于它不使用 pin 或 windows,因此该文件可以被项目的双方#included。当然,根据您的应用程序试图实现的目标,这可能会很困难,因此您可能必须进行一些重型类型的擦除。

像这样的东西:

// pin.cpp
#include <intel/pin.h>
#include "bridge.h"

void method(){
  Window* wnd = Window::Create();
  wnd.Show();
}

.

// bridge.h
class Window {
public:
  static Window* Create();
  virtual void Show()=0;
};

.

// WindowsImpl.cpp
#include <windows.h>
#include "bridge.h"

class WindowImpl : public Window {
  HWND hwnd;
public:
  bool Create(){
    hwnd = CreateWindowEx(...);
    return hwnd != NULL;
  }
  void Show() override {
    ShowWindow(hwnd,...);
  }
};
Window* Window::Create(){
  WindowImpl* newWnd = new WindowImpl();
  newWnd->Create();
  return newWnd;
}
于 2016-08-01T13:40:30.413 回答