CMAKEList飞跃运动

时间:2016-05-27 17:52:22

标签: c++ makefile cmake leap-motion

我正在尝试从跳跃动作的makefile构建一个cmakelist文件,我可以在特定的目录中编译,我需要复制/ include /和/ lib / x64 /目录。 makefile如下:

LEAP_LIBRARY := ./lib/x64/libLeap.so -Wl,-rpath,./lib/x64

Sample: Sample.cpp
    $(CXX) -Wall -g -I include Sample.cpp -o Sample $(LEAP_LIBRARY)

我尝试按如下方式构建cmakelist文件:

cmake_minimum_required(VERSION 2.8)
project(Sample)

INCLUDE_DIRECTORIES(/include/)
LINK_DIRECTORIES(/lib/x64/)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -I /include/ -Wl,-rpath,./lib/x64")

add_executable(Sample Sample.cpp )
target_link_libraries(Sample libLeap.so)

但我总是得到同样的错误:

Linking CXX executable Sample
/usr/bin/ld: can't find -lLeap
collect2: error: ld returned 1 exit status
make[2]: *** [Sample] Error 1
make[1]: *** [CMakeFiles/Sample.dir/all] Error 2
make: *** [all] Error 2

谢谢和问候。

1 个答案:

答案 0 :(得分:0)

我可以用以下几行解决:

cmake_minimum_required(VERSION 2.8)
project(Sample)
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
INCLUDE_DIRECTORIES(../include/)
LINK_DIRECTORIES(../lib/x64/)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g")

add_executable(Sample Sample.cpp )
target_link_libraries(Sample -lLeap)

此解决方案有警告但有效:

CMake Warning (dev) at CMakeLists.txt:5 (LINK_DIRECTORIES):
This command specifies the relative path

../lib/x64

as a link directory.

Policy CMP0015 is not set: link_directories() treats paths relative to the
source dir.  Run "cmake --help-policy CMP0015" for policy details.  Use the
cmake_policy command to set the policy and suppress this warning.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done
-- Build files....

删除此警告的两种方法:

cmake_minimum_required(VERSION 2.8)
project(Sample)

cmake_policy(SET CMP0015 NEW)

SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
INCLUDE_DIRECTORIES(../include/)
LINK_DIRECTORIES(lib/x64/)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g")

add_executable(Sample Sample.cpp )
target_link_libraries(Sample -lLeap)

或使用cmake .. -Wno-dev