1

So I am noob who has been studying python over the past few months. I recently discovered a python library called PyWiiUse and wanted to use it to do some fun stuff with the WiiMote. Since the library is just a wrapper of the C library WiiUse, I found I would have to install both libraries before I could start anything.

I have a mac running mountain lion and I have had some serious trouble compiling and installing the WiiUse library. The README says to use cmake to generate a MakeFile for the source code. I ran the following command after installing cmake, xcode, and xcode command line tools.

cd /build_directory
cmake /source_directory
make
make install

cmake successfully made a MakeFile, and gnu make software built and installed a static library "libwiiuse.a" and header file "wiiuse.h". The static library was installed to /usr/local/lib and the header file was installed to /usr/local/include.

I didn't know what to do with the stative library. THe README file led me to believe I would get a linked library in the form of libwiiuse.so. I read up on static libraries and learned they are just archives of compiled code. I extracted the .o files from the archive to a folder called libwiiuse and ran the following code:

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

I attempted to compile all of the ".o"(object?) files into one ".so"(shared object?) file. The result I got was unexpected.

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)

So I am pretty much stuck here. I wasn't sure if the object files were buildt for X86 64 architecture so I ran the "file" command on all of the files and got the same result for each.

Mach-O 64-bit object x86_64

I know what I want to do it probably really easy, but I have been struggling here. Can anyone help me?

karosc
  • 31
  • 2
  • Although this does directly involve a programming tool, I think the fact that the error is coming from installing a C library merits this being posted on superuser instead. – Adam Smith Jan 21 '14 at 00:09

1 Answers1

0

When linking the static wiiuse.a library on a Mac, you also need to link some Apple frameworks. Try adding the following to your 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)

Then, after creating your target, the cmake link command would look like...

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

(I thought the static lib would take care of this for us, but I was mistaken.)

chadwick.boulay
  • 1,784
  • 2
  • 12
  • 10