rx_tools icon indicating copy to clipboard operation
rx_tools copied to clipboard

Project doesn't compile - cmake build fails with `pthreads development files not found`

Open eabase opened this issue 10 months ago • 3 comments

Project doesn't compile. Please update your README, and instructions how to get this to work.

# cmake -S .. -B . -Ax64 -Wno-dev -Wno-deprecated --fresh --install-prefix 'C:\Program Files\rx_tools' -DCMAKE_BUILD_TYPE=Release

-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.26100.
-- The C compiler identification is MSVC 19.43.34808.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Could NOT find Threads (missing: THREADS_PTHREADS_WIN32_LIBRARY THREADS_PTHREADS_INCLUDE_DIR)
CMake Error at CMakeLists.txt:37 (message):
  pthreads development files not found...


-- Configuring incomplete, errors occurred!

eabase avatar Feb 25 '25 08:02 eabase

You might need pthread-win32 If you find a working version the documentation at https://github.com/rxseger/rx_tools/blob/master/cmake/FindThreads.cmake#L2 needs updating.

zuckschwerdt avatar Feb 25 '25 09:02 zuckschwerdt

Also, when we update the docs, since pthreads will generally only be missing on Windows the hint at https://github.com/rxseger/rx_tools/blob/master/CMakeLists.txt#L37 should include a hint to pthreads-win32.

zuckschwerdt avatar Feb 25 '25 09:02 zuckschwerdt

Ok, I finally got it to work. 😱

It was hard to find instructions on how to deal with pthreads for x64. You need to build it yourself...whcih required another package, vcpkg.

But we will also need pkgconfig, so might as well do that too...

Here are the steps:


# cd C:\your\gitclones

git clone --depth=1 https://github.com/microsoft/vcpkg
cd vcpkg
./bootstrap-vcpkg.bat -disableMetrics

#------------------------------------------------------
# Install:  pkgconfig
#------------------------------------------------------
.\vcpkg.exe install pkgconf

# Check if here:
.\vcpkg.exe list

# Set Temporary Environment Variables
# You can always make them permanent later.
$Env:VCPKG_DISABLE_METRICS=1                           # Disable Telemetry (maybe "ON")
$Env:PKG_CONFIG_EXECUTABLE='C:\mydev\gitclones\vcpkg'  # exe
$Env:PATH+=';C:\mydev\gitclones\vcpkg'                 # Add vcpkg to your PATH


#------------------------------------------------------
# Install:  pthreads
#------------------------------------------------------
# NOTE: 
# In VS DEV shell we get:
#	warning: The vcpkg C:\mydev\gitclones\vcpkg\vcpkg.exe is using detected vcpkg root: 
#	C:\mydev\gitclones\vcpkg and ignoring mismatched VCPKG_ROOT environment value: 
#	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg. 
#	To suppress this message, unset the environment variable or use the --vcpkg-root command line switch.
#------------------------------------------------------


# Search for pthreads variants
./vcpkg search pthread

.\vcpkg.exe install pkgconf

# Build Dynamic x64
# This will build the 'dll' and import library in '.\vcpkg\installed\x64-windows'.
# From here copy the 'lib' and 'include' folders.
vcpkg install pthreads:x64-windows

# Build Static x64
vcpkg install pthreads:x64-windows-static

...

This will build all files and for the x64 (static) you will find them, here:

# cd .\installed\x64-windows-static
# tree -C -L 3
.
+-- debug
¦   +-- lib
¦       +-- pthreadVC3d.lib
¦       +-- pthreadVCE3d.lib
¦       +-- pthreadVSE3d.lib
+-- include
¦   +-- _ptw32.h
¦   +-- pthread.h
¦   +-- sched.h
¦   +-- semaphore.h
+-- lib
¦   +-- pthreadVC3.lib
¦   +-- pthreadVCE3.lib
¦   +-- pthreadVSE3.lib
+-- share
    +-- PThreads4W
    ¦   +-- PThreads4WConfig.cmake
    +-- PThreads_windows
    ¦   +-- vcpkg-cmake-wrapper.cmake
    +-- pthread
    ¦   +-- vcpkg-cmake-wrapper.cmake
    +-- pthreads
        +-- copyright
        +-- usage
        +-- vcpkg-cmake-wrapper.cmake
        +-- vcpkg.spdx.json
        +-- vcpkg_abi_info.txt

Q: Now, what are the differences between these 3 files *.lib?

Answer: Use "VC3"

#-----------------------------------------------
# C  = no exceptions (default on most POSIX)
# CE = C++ Exception Handling
# SE = Structure Exception Handling (MSVC only)
#   -DTHREADS_PTHREADS_WIN32_EXCEPTION_SCHEME=C
#-----------------------------------------------


# Thus we can create the pthreads location variables needed by rx_tools
$THREADS_PTHREADS_INCLUDE_DIR='C:\mydev\gitclones\vcpkg\installed\x64-windows-static\include'
$THREADS_PTHREADS_WIN32_LIBRARY='C:\mydev\gitclones\vcpkg\installed\x64-windows-static\lib\pthreadVC3.lib'

cmake -S .. -B . -Ax64 -Wno-dev -Wno-deprecated --fresh --install-prefix 'C:\Program Files\rx_tools' -DCMAKE_BUILD_TYPE=Release -DTHREADS_PTHREADS_WIN32_LIBRARY="$THREADS_PTHREADS_WIN32_LIBRARY" -DTHREADS_PTHREADS_INCLUDE_DIR="$THREADS_PTHREADS_INCLUDE_DIR" --loglevel=DEBUG

cmake --build . --config Release --parallel 8

cmake --build . --config Release --target install

Done.

Q: But how to test these? A-1: No idea, but have a look in #106 A-2: You need some kind of tool that can take piped stream input from rx_fm.exe...

Supposedly these could work:

  • Sox :
  • aplay :
  • multimon-ng :

Perhaps like this:

rtl_fm -M wbfm -f 89.1M | play -r 32k -t raw -e s -b 16 -c 1 -V1 -

Of course, if you have MSYS2/Cygwin, it may help... but then we wouldn't be using all these Windows steps.

# In MSYS, gcc comes with pthreads...
pacman -Syu gcc

eabase avatar Feb 25 '25 17:02 eabase