💻

gps-sdr-simのhackplayerをmakeでコンパイルする

に公開

Windows 11 ProのWLS 2上のUbuntu 24.04.3でgps-sdr-simのplayerにあるhackplayer.cをmakeでコンパイルしたところエラーになりました。

$ make hackplayer
make: pkg-config: No such file or directory
make: pkg-config: No such file or directory
make: pkg-config: No such file or directory
cc -std=c11 -O3 -g -W -Wall      -c -o hackplayer.o hackplayer.c
hackplayer.c:22:10: fatal error: libhackrf/hackrf.h: No such file or directory
   22 | #include <libhackrf/hackrf.h>
      |          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: hackplayer.o] Error 1

pkg-configがないとのことで、インストールします。

$ which pkg-config
$sudo apt-get install pkg-config
$ which pkg-config
/usr/bin/pkg-config

続いてlibhackrfがないとのこと。

$ make hackplayer
Package libhackrf was not found in the pkg-config search path.
Perhaps you should add the directory containing `libhackrf.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libhackrf', required by 'virtual:world', not found
cc -g -o hackplayer hackplayer.o  -lm
/usr/bin/ld: hackplayer.o: in function `main':
/home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:119:(.text.startup+0x64): undefined reference to `hackrf_compute_baseband_filter_bw_round_down_lt'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:121:(.text.startup+0x6c): undefined reference to `hackrf_init'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:128:(.text.startup+0x88): undefined reference to `hackrf_open_by_serial'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:156:(.text.startup+0xf8): undefined reference to `hackrf_set_sample_rate_manual'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:165:(.text.startup+0x134): undefined reference to `hackrf_set_baseband_filter_bandwidth'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:172:(.text.startup+0x148): undefined reference to `hackrf_set_txvga_gain'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:173:(.text.startup+0x160): undefined reference to `hackrf_start_tx'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:182:(.text.startup+0x190): undefined reference to `hackrf_set_freq'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:190:(.text.startup+0x1bc): undefined reference to `hackrf_set_amp_enable'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:198:(.text.startup+0x1e8): undefined reference to `hackrf_is_streaming'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:202:(.text.startup+0x1fc): undefined reference to `hackrf_is_streaming'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:210:(.text.startup+0x228): undefined reference to `hackrf_stop_tx'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:212:(.text.startup+0x234): undefined reference to `hackrf_error_name'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:217:(.text.startup+0x258): undefined reference to `hackrf_close'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:220:(.text.startup+0x264): undefined reference to `hackrf_error_name'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:225:(.text.startup+0x280): undefined reference to `hackrf_exit'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:130:(.text.startup+0x318): undefined reference to `hackrf_error_name'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:123:(.text.startup+0x34c): undefined reference to `hackrf_error_name'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:176:(.text.startup+0x388): undefined reference to `hackrf_error_name'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:158:(.text.startup+0x3a8): undefined reference to `hackrf_error_name'
/usr/bin/ld: /home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:167:(.text.startup+0x3c8): undefined reference to `hackrf_error_name'
/usr/bin/ld: hackplayer.o:/home/kikuta/sdr/gps-sdr-sim/player/hackplayer.c:184: more undefined references to `hackrf_error_name' follow
collect2: error: ld returned 1 exit status
make: *** [Makefile:19: hackplayer] Error 1

libhackrfはhackrfに入ってるのですが、libhackrf-devなるものをインストールすればいい、みたいな記事を見かけたので入れてみました。

$ sudo apt-get install libhackrf-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libdrm-nouveau2 libdrm-radeon1 libgl1-amber-dri libglapi-mesa
  libxcb-dri2-0
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  libhackrf-dev
0 upgraded, 1 newly installed, 0 to remove and 18 not upgraded.
Need to get 0 B/34.7 kB of archives.
After this operation, 160 kB of additional disk space will be used.
Selecting previously unselected package libhackrf-dev.
(Reading database ... 45253 files and directories currently installed.)
Preparing to unpack .../libhackrf-dev_2023.01.1-9build1_arm64.deb ...
Unpacking libhackrf-dev (2023.01.1-9build1) ...
Setting up libhackrf-dev (2023.01.1-9build1) ...

makeがとおるようになりました!

$ make hackplayer
cc -g -o hackplayer hackplayer.o  -lm -lhackrf

実行形式のhackplayerが生成されています。

$ ls
Makefile   bladeplayer.c  hackplayer.c  limeplayer.c    plutoplayer.c
README.md  hackplayer     hackplayer.o  limeplayer_win  plutoplayer_win
GNSSたまごくらぶ

Discussion