Im trying to build a project which uses the Myo SDK and the LeapMotion SDK on Windows 7 with CMake, Qt Creator and MinGW 4.9.2 32bit as compiler.
The MyoSDK ist working fine but I have some problems with linking the LeapMotion SDK in CMake. I found an existing sample CMake file which says that the Windows part is not finished.
Here is my CMakeLists.txt:
cmake_minimum_required (VERSION 2.6)
project (MyoLeapController)
#set(THALMICLABSMYO_ROOT_DIR "C:/myo-sdk-win-0.9.0")
################## MYO
if(WIN32)
set(THALMICLABSMYO_ROOT_DIR
"${THALMICLABSMYO_ROOT_DIR}"
CACHE
PATH
"Directory to search for the Thalmic Labs Myo SDK")
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
set(_ARCH x86_64)
else()
set(_ARCH x86_32)
endif()
set(_SDKDIR Windows)
find_path(THALMICLABSMYO_INCLUDE_DIR
NAMES myo/libmyo.h
PATHS "${THALMICLABSMYO_ROOT_DIR}/include")
include(FindPackageHandleStandardArgs)
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
find_library(THALMICLABSMYO_LIBRARY
NAMES myo64
PATHS "${THALMICLABSMYO_ROOT_DIR}/lib"
PATH_SUFFIXES "${_SDKDIR}/${_ARCH}")
else()
find_library(THALMICLABSMYO_LIBRARY
NAMES myo32
PATHS "${THALMICLABSMYO_ROOT_DIR}/lib"
PATH_SUFFIXES "${_SDKDIR}/${_ARCH}")
endif()
find_package_handle_standard_args(ThalmicLabsMyo
DEFAULT_MSG
THALMICLABSMYO_LIBRARY
THALMICLABSMYO_INCLUDE_DIR
${_deps_check})
if(THALMICLABSMYO_FOUND)
set(THALMICLABSMYO_LIBRARIES "${THALMICLABSMYO_LIBRARY}")
set(THALMICLABSMYO_INCLUDE_DIRS "${THALMICLABSMYO_INCLUDE_DIR}")
mark_as_advanced(THALMICLABSMYO_ROOT_DIR)
endif()
mark_as_advanced(THALMICLABSMYO_INCLUDE_DIR THALMICLABSMYO_LIBRARY)
endif()
################## LEAP
IF(LEAP_INCLUDE_DIR AND LEAP_LIBRARY)
SET(LEAP_FIND_QUIETLY TRUE)
ENDIF(LEAP_INCLUDE_DIR AND LEAP_LIBRARY)
# Set locations to search
IF(UNIX)
SET(LEAP_INCLUDE_SEARCH_DIRS
/usr/include
/usr/local/include
/opt/leap/include
/opt/leap_sdk/include
/opt/include INTERNAL)
SET(LEAP_LIBRARY_SEARCH_DIRS
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/leap/lib
/opt/leap/lib64
/opt/leap_sdk/lib
/opt/leap_sdk/lib64 INTERNAL)
SET(LEAP_INC_DIR_SUFFIXES PATH_SUFFIXES leap)
ELSE(UNIX)
#WIN32
SET(LEAP_INC_DIR_SUFFIXES PATH_SUFFIXES inc)
SET(LEAP_LIB_DIR_SUFFIXES PATH_SUFFIXES lib)
ENDIF(UNIX)
# Set name of the Leap library to use
IF(APPLE)
SET(LEAP_LIBRARY_NAME libLeap.dylib)
ELSE(APPLE)
IF(UNIX)
SET(LEAP_LIBRARY_NAME libLeap.so)
ELSE(UNIX)
# TODO Different libraries are provided for compile and runtime
SET(LEAP_LIBRARY_NAME libLeap.lib)
ENDIF(UNIX)
ENDIF(APPLE)
IF(NOT LEAP_FIND_QUIETLY)
MESSAGE(STATUS "Checking for Leap")
ENDIF(NOT LEAP_FIND_QUIETLY)
# Search for header files
FIND_PATH(LEAP_INCLUDE_DIR Leap.h
PATHS ${LEAP_INCLUDE_SEARCH_PATHS}
PATH_SUFFIXES ${LEAP_INC_DIR_SUFFIXES})
# Search for library
FIND_LIBRARY(LEAP_LIBRARY ${LEAP_LIBRARY_NAME}
PATHS ${LEAP_LIBRARY_SEARCH_DIRS}
PATH_SUFFIXES ${LEAP_LIB_DIR_SUFFIXES})
SET(LEAP_INCLUDE_DIR ${LEAP_INCLUDE_DIR} CACHE STRING
"Directory containing LEAP header files")
SET(LEAP_LIBRARY ${LEAP_LIBRARY} CACHE STRING "Library name of Leap library")
SET(LEAP_INCLUDE_DIRS ${LEAP_INCLUDE_DIR} )
SET(LEAP_LIBRARIES ${LEAP_LIBRARY} )
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Leap DEFAULT_MSG LEAP_LIBRARY LEAP_INCLUDE_DIR)
MARK_AS_ADVANCED(LEAP_INCLUDE_DIR LEAP_LIBRARY)
##################
message(${LEAP_LIBRARY})
INCLUDE_DIRECTORIES(${THALMICLABSMYO_INCLUDE_DIR} ${LEAP_INCLUDE_DIRS})
add_executable(MyoLeapController main.cpp)
target_link_libraries(MyoLeapController ${THALMICLABSMYO_LIBRARY} ${LEAP_LIBRARY})
My CMake output is:
C:/LeapSDK/lib/x86/Leap.dll
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/riecker/Documents/Masterthesis/MyoLeapController-bin
I link the found Leap library exactly the same like the Myo but I get some Linker errors.
My C++ program for testing:
#include <iostream>
#include <myo/myo.hpp>
#include <Leap.h>
int main (int argc, char *argv[])
{
//myo::Hub hub("MyoLeapController");
Leap::Controller controller;
std::cout << "hi" << std::endl;
return 0;
}
The Error Message:
[ 50%] Linking CXX executable MyoLeapController.exe
CMakeFiles\MyoLeapController.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1d): undefined reference to `Leap::Controller::Controller()'
CMakeFiles\MyoLeapController.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x51): undefined reference to `Leap::Controller::~Controller()'
CMakeFiles\MyoLeapController.dir\build.make:98: recipe for target 'MyoLeapController.exe' failed
CMakeFiles\MyoLeapController.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x61): undefined reference to `Leap::Controller::~Controller()'
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/MyoLeapController.dir/all' failed
makefile:82: recipe for target 'all' failed
C:/Qt/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\MyoLeapController.dir/objects.a(main.cpp.obj): bad reloc address 0x0 in section `.ctors'
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [MyoLeapController.exe] Error 1
mingw32-make[1]: *** [CMakeFiles/MyoLeapController.dir/all] Error 2
mingw32-make: *** [all] Error 2
10:56:32: Der Prozess "C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe" wurde mit dem Rückgabewert 2 beendet.
Fehler beim Erstellen/Deployment des Projekts MyoLeapController (Kit: Desktop Qt 5.6.0 MinGW 32bit)
Bei der Ausführung von Schritt "Make"
The include of the Leap SDK is working because it can find the header files only during linking I get the problem. For including and linking I am doing the same like with the Myo SDK which is working.
Can anybody help me or have an idea about this? Thank you