1

I have downloaded linux software of cypress SDK EZ-USB FX3 Software Development Kit. Inside Cypress/cyusb_linux_1.0.5/src there's many .cpp file that I compile with make and that work perfectly. I wanted to do my own cpp project so I copy the code of one of those files and tried to compile it using CMakeLists.txt. I have the following structure:

project/
├── include/
│   └── cyusb.h
├── src/
│   └── libcyusb.cpp
├── CMakeLists.txt
└── main.cpp

When I do:

$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]

However, following this I get no response doing pkg-config --libs libusb but I did find something with:

$pkg-config --libs libusb-1.0
-lusb-1.0

So I added it to my CMakeLists.txt and right now it looks like this:

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})

When I hit make I get:

[ 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...)
J Agustin Barrachina
  • 3,501
  • 1
  • 32
  • 52

1 Answers1

2

You need to add the library with the standard CMake mechanism.

target_link_libraries(project usb-1.0)

The variable GCC_COVERAGE_LINK_FLAGS is not used in normal builds.

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62