【问题标题】:Xcode: Match-O Linker (Id) Error when building HID ExplorerXcode:构建 HID Explorer 时出现 Mach-O 链接器 (Ld) 错误
【发布时间】:2013-05-01 01:29:04
【问题描述】:

我想在 Xcode 4 中构建 HID Explorer 示例,但是当我尝试构建时,我得到了这些错误(无论是 32 还是 64):

Undefined symbols for architecture x86_64:
  "_DisposeMenu", referenced from:
      _Handle_WindowEvents in main.o
  "_GetControl32BitMaximum", referenced from:
      _Handle_EventControlDraw in main.o
  "_GetControl32BitMinimum", referenced from:
      _Handle_EventControlDraw in main.o
  "_GetControl32BitValue", referenced from:
      _Handle_EventControlDraw in main.o
  "_InvalWindowRect", referenced from:
      _SetElementTitle in main.o
  "_SetControl32BitMaximum", referenced from:
      _Update_WindowElementInfo in main.o
  "_SetControl32BitMinimum", referenced from:
      _Update_WindowElementInfo in main.o
  "_SetControl32BitValue", referenced from:
      _DisplayCurrentDeviceElementValue in main.o
  "_SetControlMaximum", referenced from:
      _Build_DeviceMenu in main.o
      _Build_ElementMenu in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我认为,缺少一个框架。谁能告诉我,是哪一个?

已经包含的框架有: CoreFoundation.framework、IOKit.framework、Carbon.framework

【问题讨论】:

    标签: xcode macos osx-mountain-lion


    【解决方案1】:

    除非您想重新编写代码本身,否则唯一有效的架构是(ppc 和 i386)。当我尝试构建包含 x86_64 的项目时,我重现了确切的错误。当我删除该架构时,项目构建并运行得很好。

    有效架构:ppc i386 或只是 i386

    【讨论】:

      【解决方案2】:

      HID Explorer 是一个 Legacy Carbon 示例,它使用 IOKit 与 HID 设备通信。您应该考虑改用 10.5 中引入的 HID 管理器。请参阅:https://developer.apple.com/library/mac/#documentation/DeviceDrivers/Conceptual/HID/intro/intro.html

      下面是一些使用 HID 管理器迭代所有连接的 HID 设备的最少代码:

      int main(int argc, const char * argv[]) 
      {
          IOHIDManagerRef tIOHIDManagerRef = NULL;
          CFSetRef deviceCFSetRef = NULL;
          IOHIDDeviceRef *tIOHIDDeviceRefs = nil;
      
          do {    // psudo try/throw block
              tIOHIDManagerRef = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
              if (!tIOHIDManagerRef) break;
      
              IOHIDManagerSetDeviceMatching(tIOHIDManagerRef, NULL);
      
              IOReturn tIOReturn = IOHIDManagerOpen(tIOHIDManagerRef, kIOHIDOptionsTypeNone);
              if (noErr != tIOReturn) break;
      
              deviceCFSetRef = IOHIDManagerCopyDevices(tIOHIDManagerRef);
              if (!deviceCFSetRef) break;
      
              CFIndex deviceIndex, deviceCount = CFSetGetCount(deviceCFSetRef);
      
              tIOHIDDeviceRefs = malloc(sizeof(IOHIDDeviceRef) * deviceCount);
              if (!tIOHIDDeviceRefs) break;
      
              CFSetGetValues(deviceCFSetRef, (const void **)tIOHIDDeviceRefs);
              CFRelease(deviceCFSetRef);
              deviceCFSetRef = NULL;
              for (deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) {
                  if (!tIOHIDDeviceRefs[deviceIndex]) continue;
      
                  // dump the HID device info 
                  // HIDDumpDeviceInfo(tIOHIDDeviceRefs[deviceIndex]);
              }
          } while (false);
      
          if (tIOHIDDeviceRefs) {
              free(tIOHIDDeviceRefs);
          }
          if (deviceCFSetRef) {
              CFRelease(deviceCFSetRef);
              deviceCFSetRef = NULL;
          }
          if (tIOHIDManagerRef) {
              CFRelease(tIOHIDManagerRef);
          }
      
          return (0);
      } // main
      

      【讨论】:

      • 你是对的,我已经改变了我的代码。但 HID Explorer 是查看连接设备的便捷工具。
      • HID 校准器示例将为每个连接的 HID 设备创建一个窗口,然后枚举每个设备的每个输入或功能元素。在 (san 空格)用于 Cocoa 版本。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 2013-06-29
      • 2013-12-03
      • 1970-01-01
      • 2017-12-20
      相关资源
      最近更新 更多