我已经下载了cypress SDK EZ-USB FX3 Software Development Kit的Linux软件。在Cypress/cyusb_linux_1.0.5/src
中,有许多.cpp
文件是我用make编译的,可以很好地工作。我想做一个自己的cpp项目,所以我复制了其中一个文件的代码,并尝试使用CMakeLists.txt
进行编译。我有以下结构:
project/
├── include/
│ └── cyusb.h
├── src/
│ └── libcyusb.cpp
├── CMakeLists.txt
└── main.cpp
当我这样做时:
$apt list --installed | grep -i libusb
libusb-1.0-0/bionic,now 2:1.0.21-2 amd64 [installed,automatic]
libusb-1.0-0-dev/bionic,now 2:1.0.21-2 amd64 [installed]
但是,在this之后,我pkg-config --libs libusb
并没有得到回应,但是我确实找到了一些东西:
$pkg-config --libs libusb-1.0
-lusb-1.0
所以我将其添加到我的CMakeLists.txt中,现在看起来像这样:
cmake_minimum_required(VERSION 3.10)
project(project)
set(CMAKE_CXX_STANDARD 14)
SET(GCC_COVERAGE_LINK_FLAGS "-lusb-1.0")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
file(GLOB SOURCES
include/*.h
src/*.cpp
main.cpp
)
add_executable(project ${SOURCES})
当我打make
时,我得到:
[ 33%] Linking CXX executable project
CMakeFiles/project.dir/src/libcyusb.cpp.o: In function `libusb_get_descriptor':
/usr/include/libusb-1.0/libusb.h:1777: undefined reference to `libusb_control_transfer'
CMakeFiles/project.dir/src/libcyusb.cpp.o: In function `libusb_get_string_descriptor':
/usr/include/libusb-1.0/libusb.h:1799: undefined reference to `libusb_control_transfer'
CMakeFiles/project.dir/src/libcyusb.cpp.o: In function `device_is_of_interest(libusb_device*)':
project/src/libcyusb.cpp:157: undefined reference to `libusb_get_device_descriptor'
CMakeFiles/project.dir/src/libcyusb.cpp.o: In function `renumerate()':
project/src/libcyusb.cpp:208: undefined reference to `libusb_get_device_list'
project/src/libcyusb.cpp:219: undefined reference to `libusb_open'
[...] ETC [...] (you got the idea...)
答案 0 :(得分:1)
您需要添加具有标准CMake机制的库。
target_link_libraries(project usb-1.0)
在常规版本中不使用变量GCC_COVERAGE_LINK_FLAGS
。