Developer documentation: Compiling hacktv - steeviebops/hacktv-gui GitHub Wiki
These instructions are for Captain Jack's fork as this needs the most pre-requisites, but will work fine with other builds too.
If your distro doesn't have a package, or you want the latest features, you will need to compile hacktv from source. Below are some examples of how to compile it, and the pre-requisites required.
Debian and derivatives:
sudo apt update
sudo apt install libc-dev g++ build-essential git cmake hackrf libhackrf-dev libavutil-dev libavdevice-dev libswresample-dev libswscale-dev libavformat-dev libavcodec-dev libfreetype6-dev
git clone https://github.com/captainjack64/hacktv.git
cd hacktv/src
make
sudo make install
This will install hacktv to /usr/local/bin.
If you need SoapySDR or fl2k support, you will need to compile these before building hacktv.
git clone https://github.com/pothosware/SoapySDR.git
mkdir SoapySDR/build
cd SoapySDR/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DPYTHON_INSTALL_DIR=/usr/lib/python3.8/dist-packages
make -j4
sudo make install
sudo ldconfig
SoapySDRUtil --info
sudo apt-get install libusb-1.0-0-dev
git clone https://gitea.osmocom.org/sdr/osmo-fl2k.git
mkdir osmo-fl2k/build
cd osmo-fl2k/build
cmake ../ -DINSTALL_UDEV_RULES=ON
make -j 3
sudo make install
sudo ldconfig
Compiling hacktv for Windows isn't essential, because you can download it from the GUI Settings tab in hacktv-gui. But if you want to do it, here's how. You'll still need some form of Linux, such as Ubuntu or Windows Subsystem for Linux (WSL). Older versions of Fedora will not work but Fedora 40 has been tested and works, albeit with an issue with osmo-fl2k as mentioned below.
Debian and derivatives (including WSL):
sudo apt update
sudo apt install gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 mingw-w64-tools git make libtool cmake yasm nasm patch dpkg-dev
git clone https://github.com/captainjack64/hacktv.git
cd hacktv/src
./build_win64.sh
Fedora:
sudo dnf install git make libtool mingw64-gcc mingw64-gcc-c++ mingw64-winpthreads-static mingw64-pkg-config cmake yasm nasm patch gettext-devel
git clone https://github.com/captainjack64/hacktv.git
cd hacktv/src
./build_win64.sh
This will produce a hacktv.exe file in the hacktv directory that was created by the git command. The Windows build also includes support for FL2000 devices.
You may encounter some of the following errors when compiling for Windows using the build_win64.sh build script. You can use the helper script at https://github.com/steeviebops/hacktv-windows-build-helpers to automatically patch the issues mentioned below.
-
Compile error (among others) during final hacktv stage: mac.c:524:9: error: implicit declaration of function 'localtime_r'; did you mean 'localtime_s'?
This error is due to a difference in how Windows expects the localtime function to be handled. Captain Jack's fork already has a fix in place for this, but not fsphil's, so the following change should be made to mac.c. The fix has been added as a conditional statement, so the code change will not affect the ability to compile for non-Windows systems.Original code (circa line 523 at time of writing):
/* Get the timezone offset */ localtime_r(×tamp, &tm); i = tm.tm_gmtoff / 1800; if(i < 0) i = -i | (1 << 5); /* Calculate Modified Julian Date */ gmtime_r(×tamp, &tm); mjd = 367.0 * (1900 + tm.tm_year) - (int) (7.0 * (1900 + tm.tm_year + (int) ((1 + tm.tm_mon + 9.0) / 12.0)) / 4.0) + (int) (275.0 * (1 + tm.tm_mon) / 9.0) + tm.tm_mday - 678987.0;
Fixed code:
/* Get the timezone offset */ #ifndef WIN32 localtime_r(×tamp, &tm); i = tm.tm_gmtoff / 1800; if(i < 0) i = -i | (1 << 5); gmtime_r(×tamp, &tm); #else localtime_s(&tm, ×tamp); i = _timezone / 1800; if(i < 0) i = -i | (1 << 5); gmtime_s(&tm, ×tamp); #endif /* Calculate Modified Julian Date */ mjd = 367.0 * (1900 + tm.tm_year) - (int) (7.0 * (1900 + tm.tm_year + (int) ((1 + tm.tm_mon + 9.0) / 12.0)) / 4.0) + (int) (275.0 * (1 + tm.tm_mon) / 9.0) + tm.tm_mday - 678987.0;
-
Compile error during ffmpeg stage: ERROR: opus not found using pkg-config
This is most likely to occur on Debian-based distros. It is due to a missing linker flag, and can be resolved as follows.
Edit src/build_win64.sh and go to the bottom of the file. You should see a line similar to the following (in the ffmpeg section):
--pkg-config=pkg-config --prefix=$PREFIX
Append--extra-ldflags="-fstack-protector"
to the end of this line, so it reads:
--pkg-config=pkg-config --prefix=$PREFIX --extra-ldflags="-fstack-protector"
In addition to this, edit the line near the very end of the file which has the following:
CROSS_HOST=$HOST- make -j4 EXTRA_LDFLAGS="-static" EXTRA_PKGS="libusb-1.0"
This line should now read:
CROSS_HOST=$HOST- make -j4 EXTRA_LDFLAGS="-static -fstack-protector" EXTRA_PKGS="libusb-1.0"
Save these changes, and hacktv should now compile successfully. -
Compile error (among others) during osmo-fl2k stage: fl2k_fm.c:455:35: error: passing argument 1 of 'getopt_long' makes pointer from integer without a cast
This issue is most likely to occur on distros with the GCC 14 compiler, and is due to a bug in the osmo-fl2k code. fsphil has produced a patch file for this, which I have reproduced below. The easiest way to resolve this is to run the compilation until it fails at this point, and then save the patch below to a file called osmo-fl2k.diff in the hacktv/src directory. Now run the the following commands. If you see the message "patching file getopt.h", then the patch has been successfully applied, and compilation should now work normally on any subsequent attempt.cd build_win64/osmo-fl2k/src/getopt/ patch < ../../../../osmo-fl2k.diff
osmo-fl2k.diff:
--- a/src/getopt/getopt.h +++ b/src/getopt/getopt.h @@ -142,23 +142,23 @@ struct option /* Many other libraries have conflicting prototypes for getopt, with differences in the consts, in stdlib.h. To avoid compilation errors, only prototype getopt for the GNU C library. */ -extern int getopt (int __argc, char *const *__argv, const char *__shortopts); +extern int getopt (int argc, char *const *argv, const char *shortopts); # else /* not __GNU_LIBRARY__ */ extern int getopt (); # endif /* __GNU_LIBRARY__ */ # ifndef __need_getopt -extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, - const struct option *__longopts, int *__longind); -extern int getopt_long_only (int __argc, char *const *__argv, - const char *__shortopts, - const struct option *__longopts, int *__longind); +extern int getopt_long (int argc, char *const *argv, const char *shortopts, + const struct option *longopts, int *longind); +extern int getopt_long_only (int argc, char *const *argv, + const char *shortopts, + const struct option *longopts, int *longind); /* Internal only. Users should not call this directly. */ -extern int _getopt_internal (int __argc, char *const *__argv, - const char *__shortopts, - const struct option *__longopts, int *__longind, - int __long_only); +extern int _getopt_internal (int argc, char *const *argv, + const char *shortopts, + const struct option *longopts, int *longind, + int long_only); # endif #else /* not __STDC__ */ extern int getopt ();
First, you'll need to install the MacOS developer tools. The quickest way to do this is to run git from the Terminal. If the tools are not installed, you'll be prompted to install them.
Secondly, you'll need Homebrew installed.
Once installed, run the following:
brew install pkgconf ffmpeg hackrf freetype
git clone https://github.com/captainjack64/hacktv.git
cd hacktv/src
make
make install
This will install hacktv to /usr/local/bin.
freetype is only required for Captain Jack's fork, it can be left out if not using it.