链接两个SDK库时,CMake链接失败

时间:2018-01-24 10:55:50

标签: c++ cmake clion

在Windows 10 64位上使用Cygwin作为工具链。我是C ++的新手。

问题:构建项目时,我收到一些未定义的引用错误。由于我没有收到任何其他错误,我怀疑链接器在链接库时遇到问题。以下错误消息:

C:\Users\xxx\.CLion2017.3\system\cygwin_cmake\bin\cmake.exe --build 
C:\PhD\test\ICMI2017Demo\cmake-build-debug --target ICMI2017Demo -- -j 4
[ 50%] Linking CXX executable ICMI2017Demo.exe
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `LeapToUHDirection':  /cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:14: undefined reference to `Ultrahaptics::Alignment::fromTrackingDirectionToDeviceDirection(Ultrahaptics::Vector3 const&) const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:14:(.text+0xf0): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Ultrahaptics::Alignment::fromTrackingDirectionToDeviceDirection(Ultrahaptics::Vector3 const&) const'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `LeapToUHPosition':
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:21: undefined reference to `Ultrahaptics::Alignment::fromTrackingPositionToDevicePosition(Ultrahaptics::Vector3 const&) const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:21:(.text+0x153): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Ultrahaptics::Alignment::fromTrackingPositionToDevicePosition(Ultrahaptics::Vector3 const&) const'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `emitterCallback(Ultrahaptics::TimePointStreaming::Emitter const&, Ultrahaptics::TimePointStreaming::OutputInterval&, Ultrahaptics::HostTimePoint const&, void*)':
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:94: undefined reference to `Ultrahaptics::TimePointStreaming::OutputInterval::begin()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:94:(.text+0x82b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Ultrahaptics::TimePointStreaming::OutputInterval::begin()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:94: undefined reference to `Ultrahaptics::TimePointStreaming::OutputInterval::end()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:94:(.text+0x83b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Ultrahaptics::TimePointStreaming::OutputInterval::end()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:94: undefined reference to `Ultrahaptics::TimePointStreaming::OutputIntervalIterator::operator<(Ultrahaptics::TimePointStreaming::OutputIntervalIterator const&) const'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:94:(.text+0x84b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Ultrahaptics::TimePointStreaming::OutputIntervalIterator::operator<(Ultrahaptics::TimePointStreaming::OutputIntervalIterator const&) const'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:100: undefined reference to `Ultrahaptics::TimePointStreaming::OutputIntervalIterator::operator->()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:100:(.text+0x8bb): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Ultrahaptics::TimePointStreaming::OutputIntervalIterator::operator->()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:100: undefined reference to `Ultrahaptics::TimePointStreaming::TimePointOnOutputInterval::persistentControlPoint(unsigned int)'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:100:(.text+0x8c8): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Ultrahaptics::TimePointStreaming::TimePointOnOutputInterval::persistentControlPoint(unsigned int)'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:101: undefined reference to `Ultrahaptics::TimePointStreaming::OutputIntervalIterator::operator->()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:101:(.text+0x8ec): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Ultrahaptics::TimePointStreaming::OutputIntervalIterator::operator->()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:101: undefined reference to `Ultrahaptics::TimePointStreaming::TimePointOnOutputInterval::persistentControlPoint(unsigned int)'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:101:(.text+0x8f9): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Ultrahaptics::TimePointStreaming::TimePointOnOutputInterval::persistentControlPoint(unsigned int)'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:103: undefined reference to `Ultrahaptics::TimePointStreaming::OutputIntervalIterator::operator->()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:103:(.text+0x91e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Ultrahaptics::TimePointStreaming::OutputIntervalIterator::operator->()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:103: undefined reference to `Ultrahaptics::TimePointStreaming::TimePointOnOutputInterval::persistentControlPoint(unsigned int)'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:103:(.text+0x92b): additional relocation overflows omitted from the output
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:104: undefined reference to `Ultrahaptics::TimePointStreaming::OutputIntervalIterator::operator->()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:104: undefined reference to `Ultrahaptics::TimePointStreaming::TimePointOnOutputInterval::persistentControlPoint(unsigned int)'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:94: undefined reference to `Ultrahaptics::TimePointStreaming::OutputIntervalIterator::operator++()'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `main':
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:145: undefined reference to `Leap::Controller::Controller()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:146: undefined reference to `Leap::Controller::setPolicyFlags(Leap::Controller::PolicyFlag) const'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:147: undefined reference to `Leap::Controller::addListener(Leap::Listener&)'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:150: undefined reference to `Ultrahaptics::TimePointStreaming::Emitter::Emitter()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:151: undefined reference to `Ultrahaptics::TimePointStreaming::Emitter::setMaximumControlPointCount(unsigned int)'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:156: undefined reference to `Ultrahaptics::TimePointStreaming::Emitter::setEmissionCallback(void (*)(Ultrahaptics::TimePointStreaming::Emitter const&, Ultrahaptics::TimePointStreaming::OutputInterval&, Ultrahaptics::HostTimePoint const&, void*), void*)'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:157: undefined reference to `Ultrahaptics::TimePointStreaming::Emitter::start()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:189: undefined reference to `Ultrahaptics::TimePointStreaming::Emitter::stop()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:191: undefined reference to `Ultrahaptics::TimePointStreaming::Emitter::start()'
/cygdrive/c/PhD/test/ICMI2017Demo/main.cpp:150: undefined reference to `Ultrahaptics::TimePointStreaming::Emitter::~Emitter()'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `__static_initialization_and_destruction_0':
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:8: undefined reference to `Ultrahaptics::Alignment::Alignment()'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `TranslatedBone::TranslatedBone(Leap::Bone const&)':
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:33: undefined reference to `Leap::Bone::nextJoint() const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:34: undefined reference to `Leap::Bone::prevJoint() const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:36: undefined reference to `Leap::Bone::basis() const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:48: undefined reference to `Leap::Bone::type() const'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `TranslatedFinger::TranslatedFinger(Leap::Finger&)':
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:77: undefined reference to `Leap::Pointable::tipVelocity() const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:79: undefined reference to `Leap::Bone::Bone()'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:84: undefined reference to `Leap::Finger::bone(Leap::Bone::Type) const'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `Leap::Pointable::~Pointable()':
C:/PhD/code/libraries/LeapSDK/include/Leap.h:129: undefined reference to `Leap::Interface::~Interface()'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `Leap::Pointable::~Pointable()':
C:/PhD/code/libraries/LeapSDK/include/Leap.h:129: undefined reference to `Leap::Interface::~Interface()'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `TranslatedHand::TranslatedHand(Leap::Hand const&)':
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:98: undefined reference to `Leap::Hand::basis() const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:99: undefined reference to `Leap::Hand::basis() const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:100: undefined reference to `Leap::Hand::basis() const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:101: undefined reference to `Leap::Hand::palmPosition() const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:102: undefined reference to `Leap::Hand::palmVelocity() const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:103: undefined reference to `Leap::Hand::palmNormal() const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:105: undefined reference to `Leap::Hand::fingers() const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:105: undefined reference to `Leap::FingerList::begin() const'
/cygdrive/c/PhD/test/ICMI2017Demo/HapticSurface/LeapMotionDataConversion.hpp:105: undefined reference to `Leap::FingerList::end() const'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `LeapListening::onFrame(Leap::Controller const&)':
/cygdrive/c/PhD/test/ICMI2017Demo/main.h:48: undefined reference to `Leap::Controller::frame(int) const'
/cygdrive/c/PhD/test/ICMI2017Demo/main.h:49: undefined reference to `Leap::Frame::hands() const'
/cygdrive/c/PhD/test/ICMI2017Demo/main.h:53: undefined reference to `Leap::HandList::isEmpty() const'
/cygdrive/c/PhD/test/ICMI2017Demo/main.h:62: undefined reference to `Leap::HandList::begin() const'
/cygdrive/c/PhD/test/ICMI2017Demo/main.h:62: undefined reference to `Leap::HandList::end() const'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `Leap::ConstListIterator<Leap::FingerList, Leap::Finger>::operator*() const':
C:/PhD/code/libraries/LeapSDK/include/Leap.h:3448: undefined reference to `Leap::FingerList::operator[](int) const'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `Leap::ConstListIterator<Leap::HandList, Leap::Hand>::operator*() const':
C:/PhD/code/libraries/LeapSDK/include/Leap.h:3448: undefined reference to `Leap::HandList::operator[](int) const'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `Leap::Frame::~Frame()':
C:/PhD/code/libraries/LeapSDK/include/Leap.h:4634: undefined reference to `Leap::Interface::~Interface()'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `Leap::HandList::~HandList()':
C:/PhD/code/libraries/LeapSDK/include/Leap.h:3883: undefined reference to `Leap::Interface::~Interface()'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `Leap::Hand::~Hand()':
C:/PhD/code/libraries/LeapSDK/include/Leap.h:1096: undefined reference to `Leap::Interface::~Interface()'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `Leap::Bone::~Bone()':
C:/PhD/code/libraries/LeapSDK/include/Leap.h:662: undefined reference to `Leap::Interface::~Interface()'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o: In function `Leap::FingerList::~FingerList()':
C:/PhD/code/libraries/LeapSDK/include/Leap.h:3622: undefined reference to `Leap::Interface::~Interface()'
CMakeFiles/ICMI2017Demo.dir/main.cpp.o:main.cpp:(.rdata$.refptr._ZN12Ultrahaptics9AlignmentD1Ev[.refptr._ZN12Ultrahaptics9AlignmentD1Ev]+0x0): undefined reference to `Ultrahaptics::Alignment::~Alignment()'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/ICMI2017Demo.dir/build.make:98: ICMI2017Demo.exe] Error 1
make[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/ICMI2017Demo.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/ICMI2017Demo.dir/rule] Error 2
make: *** [Makefile:118: ICMI2017Demo] Error 2

我试过:我使用了不同的方法来链接我的库,例如相对路径(不起作用),绝对路径(显示上述错误),使用CMake环境变量来指定路径(同样的错误)。我也尝试重新下载/重新安装SDK(也确保它们遵循64位系统)并且没有变化。最后,我尝试将库文件复制到项目解决方案的文件夹中(如果链接器无法处理其外部的搜索),但仍然存在相同的错误。

在SO中发布的原因而不是相应的网站是因为我在两个SDK(Leap Motion SDK和Ultrahaptic)上都收到了未定义的错误消息,因此倾向于我的不称职而不是特定的库故障。

请提供建议和任何可能的想法。

最后我当前的CMakeLists.txt:

cmake_minimum_required(VERSION 3.8)
project(Demo)

set(CMAKE_CXX_STANDARD 11)

# Include the Ultrahaptics SDK
find_package(Ultrahaptics)

set(ULTRAHAPTICS_INCLUDE_DIR /cygdrive/c/Program\ Files/Ultrahaptics/include/)
include_directories(${ULTRAHAPTICS_INCLUDE_DIR})

# Include the Leap Motion SDK
include_directories(C:/PhD/code/libraries/LeapSDK/include/)

set(SOURCE_FILES main.cpp main.h )
add_executable(Demo ${SOURCE_FILES})

# Link the Ultrahaptics and Leap Motion libraries
link_directories(${PROJECT_SOURCE_DIR}/libraries/)
set(ULTRAHAPTICS_LIBRARIES ${PROJECT_SOURCE_DIR}/libraries/libusb-1.0.lib ${PROJECT_SOURCE_DIR}/libraries/Ultrahaptics.lib)
target_link_libraries(Demo ${ULTRAHAPTICS_LIBRARIES} ${PROJECT_SOURCE_DIR}/libraries/Leap.lib)

0 个答案:

没有答案