CMAKE列表跳跃动作

CMAKEList leap motion

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

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

感谢和问候。

我可以用以下几行来解决:

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