0

I am trying to connect a thermal-camera (Tau2, flir) to an iMX8-M+ Board with an Yocto-Image on it. The error occurs in the make command for the libthermalgrabber. The error does NOT occur, when i make the grabber within my docker-container in VSCode on windows.

Error:

aarch64-poky-linux/bin/ld: cannot find -lusb-1.0
collect2: error: ld returned 1 exit status

Some outputs I tried to determine whether libusb was actually installed (I tried 1.0.26 as well, but in the working container is 1.0.23 installed, that is why I chose that version):

root@ucm-imx8m-plus:~/tau_stuff/libthermalgrabber# apt-cache policy libusb-1.0*
libusb-1.0-0-dev:
  Installed: 2:1.0.23-2build1
  Candidate: 2:1.0.23-2build1
  Version table:
 *** 2:1.0.23-2build1 100
        100 /var/lib/dpkg/status
libusb-1.0-doc:
  Installed: 2:1.0.23-2build1
  Candidate: 2:1.0.23-2build1
  Version table:
 *** 2:1.0.23-2build1 100
        100 /var/lib/dpkg/status
libusb-1.0-0:
  Installed: 2:1.0.23-2build1
  Candidate: 2:1.0.23-2build1
  Version table:
 *** 2:1.0.23-2build1 100
        100 /var/lib/dpkg/status


root@ucm-imx8m-plus:~/tau_stuff/libthermalgrabber# dpkg -l | grep libusb
ii  libusb-1.0-0:arm64                                                2:1.0.23-2build1                                            arm64        userspace USB programming library
ii  libusb-1.0-0-dev:arm64                                            2:1.0.23-2build1                                            arm64        userspace USB programming library development files
ii  libusb-1.0-doc                                                    2:1.0.23-2build1                                            all          documentation for userspace USB programming

root@ucm-imx8m-plus:/usr/include/libusb-1.0# ls /usr/include/libusb-1.0/libusb.h 
/usr/include/libusb-1.0/libusb.h

root@ucm-imx8m-plus:/usr/include/libusb-1.0# dpkg -L libusb-1.0-0-dev
/.
/usr
/usr/include
/usr/include/libusb-1.0
/usr/include/libusb-1.0/libusb.h
/usr/lib
/usr/lib/aarch64-linux-gnu
/usr/lib/aarch64-linux-gnu/libusb-1.0.a
/usr/lib/aarch64-linux-gnu/pkgconfig
/usr/lib/aarch64-linux-gnu/pkgconfig/libusb-1.0.pc
/usr/share
/usr/share/doc
/usr/share/doc/libusb-1.0-0-dev
/usr/share/doc/libusb-1.0-0-dev/copyright
/usr/lib/aarch64-linux-gnu/libusb-1.0.so
/usr/share/doc/libusb-1.0-0-dev/README
/usr/share/doc/libusb-1.0-0-dev/changelog.Debian.gz

root@ucm-imx8m-plus:/usr/include/libusb-1.0# dpkg -L libusb-1.0-0
/.
/lib
/lib/aarch64-linux-gnu
/lib/aarch64-linux-gnu/libusb-1.0.so.0.2.0
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libusb-1.0-0
/usr/share/doc/libusb-1.0-0/README
/usr/share/doc/libusb-1.0-0/changelog.Debian.gz
/usr/share/doc/libusb-1.0-0/copyright
/lib/aarch64-linux-gnu/libusb-1.0.so.0
root@ucm-imx8m-plus:/usr/include/libusb-1.0# 

root@ucm-imx8m-plus:/usr/include/libusb-1.0# dpkg-query -S /usr/lib/aarch64-linux-gnu/
libusb-1.0-0-dev:arm64: /usr/lib/aarch64-linux-gnu

The library that is being searched is within the CMakeLists.txt of the project at

link_libraries (usb-1.0)

The camera itself is recognized as.. (It is NOT recognized as a camera, that is normal. It has a RS232 to USB Adapter attached)

root@ucm-imx8m-plus:~/tau_stuff/libthermalgrabber# lsusb
Bus 003 Device 001: ID 1d6b:0002
Bus 001 Device 001: ID 1d6b:0002
Bus 004 Device 001: ID 1d6b:0003
Bus 002 Device 001: ID 1d6b:0003
--> Bus 003 Device 004: ID 0403:6010 <--

I'll attach the CMakeLists.txt here, maybe that has any clues in it:

set( CMAKE_BUILD_TYPE RelWithDebInfo )
set( CMAKE_CXX_FLAGS "-std=c++11" )
#set( CMAKE_CXX_FLAGS "-fpermissive -std=c++11" )
set( CMAKE_VERBOSE_MAKEFILE on )
set( TARGET thermalgrabber )
set( ROOT ./ )
set( LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib )
set( TEAXLIB_VERSION_MAJOR 1 )
set( TEAXLIB_VERSION_MINOR 2 )
set( TEAXLIB_VERSION_PATCH 0 )
set( TEAXLIB_VERSION_STRING ${TEAXLIB_VERSION_MAJOR}.${TEAXLIB_VERSION_MINOR}.${TEAXLIB_VERSION_PATCH} )


#set(USE_FTDI_LIB 1)

cmake_minimum_required(VERSION 2.8)

if (WIN32)

    MESSAGE("Setup for windows")

    if (USE_FTDI_LIB)

      MESSAGE("Using ftdi lib")
      ADD_DEFINITIONS(-DUSE_FTDI)

      include_directories (
        ${CMAKE_CURRENT_SOURCE_DIR}/src/inc
      )

      link_directories (
        ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/ftdi_i386
      )

      link_libraries (
        ftd2xx
      )

    elseif (NOT USE_FTDI_LIB)

      MESSAGE("Using libusb")

      include_directories (
        ${CMAKE_CURRENT_SOURCE_DIR}/src/inc
      )

      link_directories (
        ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/MingGW32/dll
      )

      link_libraries (
        libusb-1.0
      )

    endif(USE_FTDI_LIB)

elseif (NOT WIN32)

    MESSAGE("Setup for linux")

    if (USE_FTDI_LIB)

      MESSAGE("Not implemented")

    elseif (NOT USE_FTDI_LIB)

      MESSAGE("Using libusb")

      include_directories (
        /usr/include/libusb-1.0
        /usr/local/include/libusb-1.0

      )

      link_directories (
        /usr/lib/x86_64-linux-gnu
        /usr/local/lib
      )

      link_libraries (
        usb-1.0
      )

    endif (USE_FTDI_LIB)

endif(WIN32)

#unix:CONFIG(release, debug|release): LIBS += -L/usr/include/libusb-1.0 -libusb-1.0

set( SOURCES

    ${CMAKE_CURRENT_SOURCE_DIR}/src/thermalgrabber.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/inc/thermalgrabber.h

    ${CMAKE_CURRENT_SOURCE_DIR}/src/thermograbber.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/src/thermograbber.h

    ${CMAKE_CURRENT_SOURCE_DIR}/src/tauinterface.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/src/tauinterface.h

    ${CMAKE_CURRENT_SOURCE_DIR}/src/tauimagedecoder.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/src/tauimagedecoder.h

    ${CMAKE_CURRENT_SOURCE_DIR}/src/taucom.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/src/taucom.h

    ${CMAKE_CURRENT_SOURCE_DIR}/src/fastftdi.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/src/fastftdi.h

    ${CMAKE_CURRENT_SOURCE_DIR}/src/crc.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/src/crc.h
)

include_directories (
    ${ROOT}
    ${THERMALGRABBER}
    ${CMAKE_CURRENT_BINARY_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/inc # public header
    ${CMAKE_CURRENT_SOURCE_DIR}/src # internal headers
)

link_directories (
    ${CMAKE_CURRENT_SOURCE_DIR}/lib
    ${CMAKE_CURRENT_SOURCE_DIR}/src/lib
    #${CMAKE_CURRENT_SOURCE_DIR}/src/lib/ftdi_i386
)

add_library( ${TARGET} SHARED ${SOURCES} )
set_target_properties( ${TARGET} PROPERTIES VERSION ${TEAXLIB_VERSION_STRING} SOVERSION ${TEAXLIB_VERSION_MAJOR} )
install( TARGETS ${TARGET} DESTINATION ${CMAKE_SOURCE_DIR}/lib )

target_link_libraries(
    ${TARGET}
    pthread
)

Any help is appreciated. The system does NOT have any access to the internet and is not supposed to, so installing via apt install libusb-dev or alike is not viable. I installed those packages with .deb files.

kremerf
  • 21
  • 5
  • The first `make` error could be resolved with changeing link_libraries to target_link_libraries.. But now I get the same error within the second part of the official SDK, that is using just a makefile instead of a CMakeLists. – kremerf Aug 23 '22 at 14:10
  • "cannot find PACKAGE_NAME" - You link (by using `link_libraries`/`target_link_libraries`) with a **library**, not with a **package**. The error message "cannot find -lusb-1.0" means that the linker can find the file corresponding to the `usb-1.0` neither under predefined (default) directories nor under directories passed to it directly. BTW, since you have `libusb-1.0.pc` file, it is better to use `pkg-config` for obtain information about the library: https://stackoverflow.com/questions/29191855/what-is-the-proper-way-to-use-pkg-config-from-cmake – Tsyvarev Aug 23 '22 at 23:15
  • Added `find_package (PkgConfig REQUIRED)` and `pkg_check_modules(MY_PKG REQUIRED IMPORTED_TARGET libusb-1.0)` to the CMakeLists. Didnt work. Tried `pkg-config --modversion libusb-1.0`, didnt work. Added the libusb-1.0pc Path to pkg-config and it did work. I fear, that this is not a permanent solution. – kremerf Aug 24 '22 at 07:33
  • Just for my own sanity, whilst libusb of course is a library, you usually install it with a package-manager (apt-get, aptitude or with a debian-package), and I find it with pkg-config, which is not lib-config. Seems as if there is some fluidity between package and library, isn't it? – kremerf Aug 24 '22 at 07:36
  • With a package manager you install a **package** which **provides** a **library**. Sometimes name of the package is same as name of the library, but sometimes they differ. It could be possible that a single package provides multiple libraries, and you may choose to which package's library you want to link. `pkg-config` works with *packages* (but which names could differ from ones installed with a package manager) and returns information about all libraries from that package. – Tsyvarev Aug 24 '22 at 07:45
  • "Tried `pkg-config --modversion libusb-1.0`, didnt work." - Looks like something wrong with your environment, so standard utilities (linker, pkg-config) doesn't search by default under `/usr/lib/aarch64-linux-gnu/` directory, which you assume to be "standard" one. If you don't want to explore that problem, then you could explicitly add this directory as search path. For a linker this could be done using `link_directories`. – Tsyvarev Aug 24 '22 at 07:50
  • Adding the path to the `link_directories` ( /usr/lib/aarch64-linux-gnu and/or /usr/lib/aarch64-linux-gnu/pkgconfig) did not work, but since exporting the path to the `PKG_CONFIG_PATH` did work earlier, I set up that variable with `set(ENV{PKG_CONFIG_PATH} "/usr/lib/aarch64-linux-gnu/pkgconfig/")` and that did the trick. Thank you very much for the hints and tips! – kremerf Aug 24 '22 at 09:33

1 Answers1

0

The initial question was solved by changing link_libraries to target_link_libraries. It is advised to use target_link_libraries whenever possible, unfortunately I do not know why the developers of this SDK chose against it.

The second, identical, problem (this time with just a makefile) was solved similarly. I created a CMakeLists.txt that creates another Makefile, that does the same as the initial MakeFile. Here I had to add some lines, that I did not need to include in the first CMakeLists.txt however.

set(ENV{PKG_CONFIG_PATH} "/usr/lib/aarch64-linux-gnu/pkgconfig/")
find_package(PkgConfig REQUIRED)
pkg_check_modules(MY_PKG REQUIRED IMPORTED_TARGET libusb-1.0)
target_link_libraries (
    "name" PUBLIC
    PkgConfig::MY_PKG
)

As mentioned by Tsyvarev in the comments, it might be worth looking into why these paths are chosen/set.

kremerf
  • 21
  • 5