我正在尝试交叉编译libftdi for arm。当我运行Cmake时,我得到:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LIBUSB_INCLUDE_DIR (ADVANCED)
我知道LIBUSB_INCLUDE_DIR应该在libftdi根目录中找到的FindUSB1.cmake中设置。但是,我不知道如何使FindUSB1.cmake找到我已编译并放入/ opt / lib的libusb。这是默认文件:
# - Try to find the freetype library
# Once done this defines
#
# LIBUSB_FOUND - system has libusb
# LIBUSB_INCLUDE_DIR - the libusb include directory
# LIBUSB_LIBRARIES - Link these to use libusb
# Copyright (c) 2006, 2008 Laurent Montel, <montel@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
if (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
# in cache already
set(LIBUSB_FOUND TRUE)
else (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
IF (NOT WIN32)
# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
find_package(PkgConfig)
pkg_check_modules(PC_LIBUSB libusb-1.0)
ENDIF(NOT WIN32)
FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h
PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS})
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES usb-1.0
PATHS ${PC_LIBUSB_LIBDIR} ${PC_LIBUSB_LIBRARY_DIRS})
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBUSB DEFAULT_MSG LIBUSB_LIBRARIES LIBUSB_INCLUDE_DIR)
MARK_AS_ADVANCED(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES)
endif (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
在/ opt / lib中有一个目录pkconfig。在这个目录中有一个libusb-1.0.pc文件,我想这可能与该问题有关。那么我该如何让Cmake找到/opt/lib/libsub-1.0?
答案 0 :(得分:3)
不幸的是,默认的find脚本不是很强大。如果该库未位于find_library
pkg-config
搜索的one of the default directories内,您必须依靠pkg-config
来告诉您该库的位置。
在库中未注册PC_LIBUSB_LIBDIR
的(不是那么不可能)事件中,除了在调用查找脚本之前手动设置PC_LIBUSB_INCLUDEDIR
和HINTS
变量之外别无选择。这可以通过命令行(使用-D
parameter)或封闭的CMake脚本(使用set
)完成。
如果您可以自由更改查找脚本,请考虑在查找调用中添加其他FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h
HINTS $ENV{LIBUSB_ROOT}
PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS}
PATH_SUFFIXES include)
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES usb-1.0
HINTS $ENV{LIBUSB_ROOT}
PATHS ${PC_LIBUSB_LIBDIR} ${PC_LIBUSB_LIBRARY_DIRS}
PATH_SUFFIXES lib)
以使其更灵活。例如,使用环境变量作为提示是一种非常流行的机制,也适用于非Unix平台。
{{1}}