1

所以我是过去几个月一直在研究python的菜鸟。我最近发现了一个名为PyWiiUse的 python 库,并想用它来用 WiiMote 做一些有趣的事情。由于该库只是 C 库WiiUse的一个包装器,因此我发现必须先安装这两个库,然后才能开始任何操作。

我有一个运行山狮的 mac,我在编译和安装 WiiUse 库时遇到了一些严重的问题。自述文件说使用 cmake 为源代码生成 MakeFile。我在安装 cmake、xcode 和 xcode 命令行工具后运行了以下命令。

cd /build_directory
cmake /source_directory
make
make install

cmake成功制作了MakeFile,gnu make软件构建并安装了静态库“libwiiuse.a”和头文件“wiiuse.h”。静态库安装到/usr/local/lib,头文件安装到/usr/local/include。

我不知道如何处理静态库。自述文件让我相信我会得到一个 libwiiuse.so 形式的链接库。我阅读了静态库并了解到它们只是已编译代码的档案。我将 .o 文件从存档中提取到名为 libwiiuse 的文件夹中并运行以下代码:

gcc -shared -o libwiiuse.so io.o os_mac_find.o classic.o ir.o os_mac_interface.o dynamics.o motion_plus.o util.o events.o nunchuk.o wiiboard.o guitar_hero_3.o os_mac.o wiiuse.o

我试图将所有“.o”(对象?)文件编译成一个“.so”(共享对象?)文件。我得到的结果是出乎意料的。

Undefined symbols for architecture x86_64:
"_IOBluetoothNSStringFromDeviceAddress", referenced from:
  -[WiiuseDeviceInquiry collectResultsOf:] in os_mac_find.o
"_NSDefaultRunLoopMode", referenced from:
  -[WiiuseDeviceInquiry wait] in os_mac_find.o
  -[WiiuseWiimote waitForIncomingData:] in os_mac.o
"_OBJC_CLASS_$_IOBluetoothDeviceInquiry", referenced from:
  objc-class-ref in os_mac_find.o
_OBJC_CLASS_$_IOBluetoothHostController", referenced from:
  objc-class-ref in os_mac_find.o
"_OBJC_CLASS_$_NSAutoreleasePool", referenced from:
  objc-class-ref in os_mac_find.o
  objc-class-ref in os_mac_interface.o
  objc-class-ref in os_mac.o
"_OBJC_CLASS_$_NSData", referenced from:
  objc-class-ref in os_mac.o
"_OBJC_CLASS_$_NSDate", referenced from:
  objc-class-ref in os_mac_find.o
  objc-class-ref in os_mac.o
"_OBJC_CLASS_$_NSLock", referenced from:
  objc-class-ref in os_mac.o
"_OBJC_CLASS_$_NSMutableArray", referenced from:
  objc-class-ref in os_mac.o
"_OBJC_CLASS_$_NSObject", referenced from:
  _OBJC_CLASS_$_WiiuseDeviceInquiry in os_mac_find.o
  _OBJC_CLASS_$_WiiuseWiimote in os_mac.o
  _OBJC_CLASS_$_WiiuseDisconnectionMessage in os_mac.o
  _OBJC_CLASS_$_WiiuseReceivedData in os_mac.o
"_OBJC_CLASS_$_NSRunLoop", referenced from:
  objc-class-ref in os_mac_find.o
  objc-class-ref in os_mac.o
"_OBJC_METACLASS_$_NSObject", referenced from:
  _OBJC_METACLASS_$_WiiuseDeviceInquiry in os_mac_find.o
  _OBJC_METACLASS_$_WiiuseWiimote in os_mac.o
  _OBJC_METACLASS_$_WiiuseReceivedData in os_mac.o
  _OBJC_METACLASS_$_WiiuseDisconnectionMessage in os_mac.o
"__objc_empty_cache", referenced from:
  _OBJC_CLASS_$_WiiuseDeviceInquiry in os_mac_find.o
  _OBJC_METACLASS_$_WiiuseDeviceInquiry in os_mac_find.o
  _OBJC_CLASS_$_WiiuseWiimote in os_mac.o
  _OBJC_CLASS_$_WiiuseDisconnectionMessage in os_mac.o
  _OBJC_CLASS_$_WiiuseReceivedData in os_mac.o
  _OBJC_METACLASS_$_WiiuseWiimote in os_mac.o
  _OBJC_METACLASS_$_WiiuseReceivedData in os_mac.o
  ...
"__objc_empty_vtable", referenced from:
  _OBJC_CLASS_$_WiiuseDeviceInquiry in os_mac_find.o
  _OBJC_METACLASS_$_WiiuseDeviceInquiry in os_mac_find.o
  _OBJC_CLASS_$_WiiuseWiimote in os_mac.o
  _OBJC_CLASS_$_WiiuseDisconnectionMessage in os_mac.o
  _OBJC_CLASS_$_WiiuseReceivedData in os_mac.o
  _OBJC_METACLASS_$_WiiuseWiimote in os_mac.o
  _OBJC_METACLASS_$_WiiuseReceivedData in os_mac.o
  ...
"_objc_msgSend", referenced from:
  -[WiiuseDeviceInquiry initWithMemory:maxDevices:timeout:] in os_mac_find.o
  -[WiiuseDeviceInquiry start] in os_mac_find.o
  -[WiiuseDeviceInquiry wait] in os_mac_find.o
  -[WiiuseDeviceInquiry collectResultsOf:] in os_mac_find.o
  -[WiiuseDeviceInquiry run] in os_mac_find.o
  _wiiuse_os_find in os_mac_find.o
  _wiiuse_os_connect_single in os_mac_interface.o
  ...
"_objc_msgSendSuper2", referenced from:
  -[WiiuseDeviceInquiry initWithMemory:maxDevices:timeout:] in os_mac_find.o
  -[WiiuseWiimote initWithPtr:device:] in os_mac.o
  -[WiiuseWiimote dealloc] in os_mac.o
  -[WiiuseReceivedData initWithData:] in os_mac.o
  -[WiiuseReceivedData dealloc] in os_mac.o
"_objc_msgSend_fixup", referenced from:
  l_objc_msgSend_fixup_release in os_mac_find.o
  l_objc_msgSend_fixup_count in os_mac_find.o
  l_objc_msgSend_fixup_objectAtIndex_ in os_mac_find.o
  l_objc_msgSend_fixup_alloc in os_mac_find.o
  l_objc_msgSend_fixup_alloc in os_mac_interface.o
  l_objc_msgSend_fixup_release in os_mac_interface.o
  l_objc_msgSend_fixup_retain in os_mac.o
  ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

所以我几乎被困在这里。我不确定目标文件是否是为 X86 64 架构构建的,所以我对所有文件运行“文件”命令并为每个文件得到相同的结果。

Mach-O 64-bit object x86_64

我知道我想做什么可能真的很容易,但我一直在这里挣扎。谁能帮我?

4

1 回答 1

0

在 Mac 上链接静态 wiiuse.a 库时,还需要链接一些 Apple 框架。尝试将以下内容添加到您的 CMakeLists.txt:

set(PLATFORM_LIBS)
if(APPLE)
    find_library(IOBLUETOOTH_FRAMEWORK
        NAMES
        IOBluetooth)
    find_library(COREFOUNDATION_FRAMEWORK
        NAMES
        CoreFoundation)
    find_library(FOUNDATION_FRAMEWORK
        NAMES
        Foundation)
    list(APPEND PLATFORM_LIBS
        ${IOBLUETOOTH_FRAMEWORK}
        ${COREFOUNDATION_FRAMEWORK}
        ${FOUNDATION_FRAMEWORK})
endif(APPLE)

然后,在创建目标之后,cmake 链接命令看起来像......

target_link_libraries(${target}
    ${WIIUSE_LIB}
    ${PLATFORM_LIBS})

(我认为静态库会为我们解决这个问题,但我错了。)

于 2016-12-12T01:56:50.533 回答