Skip to content

Commit 9ce2b46

Browse files
committed
added support for windows
1 parent 583b2b1 commit 9ce2b46

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

README.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
python_hackrf is a cython wrapper for [hackrf](https://github.com/greatscottgadgets/hackrf).
44

5-
Before installing python_hackrf library, you must have hackrf host software installed. Because this library uses dynamic linking with an existing library file.
5+
Before installing python_hackrf library, you must have hackrf host software installed. Because this library uses dynamic linking with an existing library file. Minimum libhackrf version: 2024.02.1+ (0.9)
6+
7+
For windows users please use [additional steps](#installation-on-windows) to install python_hackrf
68

79
You can install this library using
810
```
@@ -11,8 +13,8 @@ pip install git+https://github.com/GvozdevLeonid/python_hackrf.git
1113

1214
If your hackrf files are in non-standard paths and during installation the python_hackrf cannot find hackrf.h or the library file, you can specify the paths via environment variables
1315
```
14-
export PYTHON_HACKRF_CFLAGS=path_to_hackrf.h
15-
export PYTHON_HACKRF_LDFLAGS=path_to_hackrf.(so, dylib, dll)
16+
export/set {linux and macos / windows} PYTHON_HACKRF_CFLAGS=path_to_hackrf.h
17+
export/set {linux and macos / windows} PYTHON_HACKRF_LDFLAGS=path_to_hackrf.(so, dylib, dll)
1618
```
1719

1820
## Requirements:
@@ -160,3 +162,38 @@ Please use the original hackrf documentation
160162

161163
## Notes
162164
For pyhackrf_transfer, FileBuffer (utils module) has been implemented, which will allow you to more conveniently receive and send iq data from sdr.
165+
166+
167+
## Installation on Windows
168+
To install python_hackrf, you must first install the HackRF software. Official installation instructions are available on the [HackRF documentation site](https://hackrf.readthedocs.io/en/latest/installing_hackrf_software.html).
169+
Alternatively, you can download the ZIP archive from the Releases tab of this repository. Extract the archive and move its contents to the standard location: `C:\Program Files\HackRF`
170+
171+
The HackRF directory should contain the following subfolders and files:
172+
```
173+
├── include
174+
│ └── hackrf.h
175+
└── lib
176+
├── hackrf.dll
177+
├── hackrf.lib ← for MSVC
178+
├── libhackrf.a ← for MinGW
179+
├── libusb-1.0.dll
180+
└── pthreadVC2.dll
181+
```
182+
183+
184+
In addition, the archive includes other required DLLs and dependencies to ensure proper operation of HackRF on Windows.
185+
libusb-1.0.dll
186+
pthreadVC2.dll
187+
188+
If you install hackrf yourself or via another path, set the following environment variables
189+
190+
MSVC:
191+
```
192+
set PYTHON_HACKRF_CFLAGS=/I"{path to .h file directory}"
193+
set PYTHON_HACKRF_LDFLAGS=/LIBPATH:"{path to .dll and .lib file directory}" hackrf.lib
194+
```
195+
MinGW:
196+
```
197+
set PYTHON_HACKRF_CFLAGS=-I"{path to .h file directory}"
198+
set PYTHON_HACKRF_LDFLAGS=-L"{path to .dll and .a file directory}" -lhackrf'
199+
```

setup.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,21 @@
4545
new_ldflags = environ.get('PYTHON_HACKRF_LDFLAGS', '')
4646

4747
elif PLATFORM == 'win32':
48-
pass
48+
include_path = 'C:\\Program Files\\HackRF\\include'
49+
lib_path = 'C:\\Program Files\\HackRF\\lib'
50+
51+
if environ.get('PYTHON_HACKRF_CFLAGS', None) is None:
52+
new_cflags = f'-I"{include_path}"'
53+
else:
54+
new_cflags = environ.get('PYTHON_HACKRF_CFLAGS', '')
55+
56+
if environ.get('PYTHON_HACKRF_LDFLAGS', None) is None:
57+
new_ldflags = f'-L"{lib_path}" -lhackrf'
58+
else:
59+
new_ldflags = environ.get('PYTHON_HACKRF_LDFLAGS', '')
60+
61+
environ['CL'] = f'/I"{include_path}"'
62+
environ['LINK'] = f'/LIBPATH:"{lib_path}" hackrf.lib'
4963

5064
environ['CFLAGS'] = f'{cflags} {new_cflags}'.strip()
5165
environ['LDFLAGS'] = f'{ldflags} {new_ldflags}'.strip()

0 commit comments

Comments
 (0)