dmage / co2mon

CLI for MasterKit CO2 Monitor
GNU General Public License v3.0
166 stars 50 forks source link

co2mon.c:(.text+0x114): undefined reference to `hid_get_device_info' #51

Open archywelker opened 1 year ago

archywelker commented 1 year ago

Ошибка при попытке собрать под Orange Pi Zero2. OS: Ubuntu 20.04 (4.9.170.7)

root@orangepizero2:~/co2mon/build# cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for one of the modules 'hidapi-libusb;hidapi'
-- Looking for libusb_strerror
-- Looking for libusb_strerror - not found
-- Configuring done
-- Generating done
-- Build files have been written to: /root/co2mon/build
root@orangepizero2:~/co2mon/build# make
Scanning dependencies of target co2mon
[ 25%] Building C object libco2mon/CMakeFiles/co2mon.dir/src/co2mon.c.o
/root/co2mon/libco2mon/src/co2mon.c: In function ‘co2mon_open_device’:
/root/co2mon/libco2mon/src/co2mon.c:59:39: warning: implicit declaration of function ‘hid_get_device_info’ [-Wimplicit-function-declaration]
   59 |         struct hid_device_info *hdi = hid_get_device_info(dev);
      |                                       ^~~~~~~~~~~~~~~~~~~
/root/co2mon/libco2mon/src/co2mon.c:59:39: warning: initialization of ‘struct hid_device_info *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
[ 50%] Linking C static library libco2mon.a
[ 50%] Built target co2mon
Scanning dependencies of target co2mond
[ 75%] Building C object co2mond/CMakeFiles/co2mond.dir/src/main.c.o
[100%] Linking C executable co2mond
/usr/bin/ld: ../libco2mon/libco2mon.a(co2mon.c.o): in function `co2mon_open_device':
co2mon.c:(.text+0x114): undefined reference to `hid_get_device_info'
collect2: error: ld returned 1 exit status
make[2]: *** [co2mond/CMakeFiles/co2mond.dir/build.make:85: co2mond/co2mond] Error 1
make[1]: *** [CMakeFiles/Makefile2:142: co2mond/CMakeFiles/co2mond.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
Sencudra commented 1 year ago

@archywelker I had the same error, and it might be because of the version of the libhidapi-dev package you have installed. You can check this by running dpkg --list | grep hid. In my case, I had version 0.11.2-1 installed using apt-get, but the latest one is 0.13.1. And hid_get_device_info is pretty new API and available since 0.13. So, just update the package to the latest version, and you should be good to go!

Personally, I'm a newbie with all this apt-get and cmake stuff, and I didn't succeed in installing the latest version of the libhidapi-dev package, anything newer than version 0.11.2-1. So, I decided to build libhidapi-dev from source. Here are the steps to do it:

  1. First, download the source code from the hidapi repository. All the instructions on how to build a standalone package from the source code are available there.
  2. Install the libudev-dev and libusb-1.0-0-dev packages as it is said in the instructions provided in the repository's BUILD.md.
  3. Build and install the standalone package according to the instructions in the BUILD.cmake.md file.
  4. Once hidapi is installed, you can build co2mon. To do so, adjust the CMake file in the repository to use the standalone package. Replace pkg_search_module(HIDAPI REQUIRED hidapi-libusb hidapi) withfind_package(hidapi REQUIRED). Then replace target_link_libraries(co2mon ${HIDAPI_LIBRARIES}) with target_link_libraries(co2mon PRIVATE hidapi::hidapi).

Without doubt not the best way, but it worked for me :)

d8rt8v commented 1 year ago

Solution by @Sencudra worked but i get an error

root@ubuntu:~/co2mon/build/co2mond# ./co2mond 
hid_open: error
Unable to open CO2 device
hid_open: error

Yet i have my sensor plugged in

root@ubuntu:~/co2mon/build/co2mond# lsusb 
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 04d9:a052 Holtek Semiconductor, Inc. USB-zyTemp
Bus 001 Device 002: ID 10c4:ea60 Silicon Labs CP210x UART Bridge
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Update: It works using sudo ./co2mond

nickolay commented 10 months ago

Note that the dependency was introduced recently in #47 to auto-detect whether a decoding step is necessary.

You might find it easier to build from an older revision (git checkout f47ec3d7e72ad4b8bc163a515b6e66bd94a6b02e) and run co2mond -n if your device requires so.