bongozone/vcvrack-rtlsdr

Problem statically linking libusb and librtlsdr

Closed this issue · 3 comments

Daniele Zerbini Hi Jon, the makefile works for me, just having to add the env path to pkg-config, and change the libusb name into libusb-1.0 (that's the name of the library installed on Windows). The plugin works, but there are still calls to the external dlls, i.e. if I remove the installed dlls, the plugin won't load. I'll try to investigate some more, may be other win-specific flags could do the trick?

Hi Jon, I tried some more options with makefile, but no results until now, either the build fails or when it complete succesfully the dynamic calls are still there when I load the plugin into Rack.
It seems to me that the issue definitely involves how to statically build against librtlstd and statically resolve the dependency on libusb.

I drop here 3 items:

  1. the console from my make command, with the fresh files pulled down from the master repository (using your last makefile);
  2. a screenshot of Rack with the plugin loaded;
  3. a printout of the Process Monitor utility, with evidence of the calls to the dynamic libraries.

The console output:

danielez@sfmi-nb-tec113 MINGW64 /vcvrack/Rack-0.5.0/plugins/vcvrack-rtlsdr
$ make
Makefile:27: warning: overriding recipe for target 'dist'
../../plugin.mk:36: warning: ignoring old recipe for target 'dist'
g++ -I/mingw64/include/libusb-1.0 -IC:/msys64/mingw64/include/ -IC:/msys64/mingw64/include/libusb-1.0 -fPIC -I../../include -I../../dep/include -MMD -g -O3 -march=nocona -ffast-math -fno-finite-math-only -Wall -Wextra -Wno-unused-parameter -DARCH_WIN -D_USE_MATH_DEFINES  -Wsuggest-override -std=c++11 -c -o build/src/PQ.cpp.o src/PQ.cpp
g++ -I/mingw64/include/libusb-1.0 -IC:/msys64/mingw64/include/ -IC:/msys64/mingw64/include/libusb-1.0 -fPIC -I../../include -I../../dep/include -MMD -g -O3 -march=nocona -ffast-math -fno-finite-math-only -Wall -Wextra -Wno-unused-parameter -DARCH_WIN -D_USE_MATH_DEFINES  -Wsuggest-override -std=c++11 -c -o build/src/sdr/SDR.cpp.o src/sdr/SDR.cpp
cc -I/mingw64/include/libusb-1.0 -IC:/msys64/mingw64/include/ -IC:/msys64/mingw64/include/libusb-1.0 -fPIC -I../../include -I../../dep/include -MMD -g -O3 -march=nocona -ffast-math -fno-finite-math-only -Wall -Wextra -Wno-unused-parameter -DARCH_WIN -D_USE_MATH_DEFINES  -c -o build/src/sdr/convenience.c.o src/sdr/convenience.c
src/sdr/convenience.c:32:0: warning: "_USE_MATH_DEFINES" redefined
 #define _USE_MATH_DEFINES

<command-line>:0:0: note: this is the location of the previous definition
src/sdr/convenience.c: In function 'atofs':
src/sdr/convenience.c:51:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
    suff *= 1e3;
    ~~~~~^~~~~~
src/sdr/convenience.c:52:3: note: here
   case 'm':
   ^~~~
src/sdr/convenience.c:54:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
    suff *= 1e3;
    ~~~~~^~~~~~
src/sdr/convenience.c:55:3: note: here
   case 'k':
   ^~~~
src/sdr/convenience.c: In function 'atoft':
src/sdr/convenience.c:78:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
    suff *= 60;
    ~~~~~^~~~~
src/sdr/convenience.c:79:3: note: here
   case 'm':
   ^~~~
src/sdr/convenience.c:81:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
    suff *= 60;
    ~~~~~^~~~~
src/sdr/convenience.c:82:3: note: here
   case 's':
   ^~~~
cc -I/mingw64/include/libusb-1.0 -IC:/msys64/mingw64/include/ -IC:/msys64/mingw64/include/libusb-1.0 -fPIC -I../../include -I../../dep/include -MMD -g -O3 -march=nocona -ffast-math -fno-finite-math-only -Wall -Wextra -Wno-unused-parameter -DARCH_WIN -D_USE_MATH_DEFINES  -c -o build/src/sdr/rtl-sdr.c.o src/sdr/rtl-sdr.c
src/sdr/rtl-sdr.c:76:0: warning: "_USE_MATH_DEFINES" redefined
 #define _USE_MATH_DEFINES

<command-line>:0:0: note: this is the location of the previous definition
src/sdr/rtl-sdr.c: In function 'polar_disc_lut':
src/sdr/rtl-sdr.c:648:31: warning: left shift of negative value [-Wshift-negative-value]
   return (cj > 0) ? 1<<13 : -1<<13;
                               ^~
src/sdr/rtl-sdr.c: In function 'mark_shared_buffer':
src/sdr/rtl-sdr.c:959:9: warning: statement with no effect [-Wunused-value]
  ss_busy[0];
  ~~~~~~~^~~
src/sdr/rtl-sdr.c: In function 'controller_thread_fn':
src/sdr/rtl-sdr.c:1305:3: warning: implicit declaration of function 'gettimeofday'; did you mean 'mingw_gettimeofday'? [-Wimplicit-function-declaration]
   gettimeofday(&tod, NULL);
   ^~~~~~~~~~~~
   mingw_gettimeofday
src/sdr/rtl-sdr.c: In function 'RtlSdr_init':
src/sdr/rtl-sdr.c:1858:21: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
  radio->rack_buffer = &demod.rack_buffer;
                     ^
src/sdr/rtl-sdr.c:1804:8: warning: unused variable 'freq' [-Wunused-variable]
  char* freq = "99.5M";
        ^~~~
g++ -o plugin.dll build/src/PQ.cpp.o build/src/sdr/SDR.cpp.o build/src/sdr/convenience.c.o build/src/sdr/rtl-sdr.c.o -L/mingw64/lib -LC:/msys64/mingw64/lib -lusb-1.0 -lrtlsdr -lusb-1.0 -shared -L../../ -lRack

danielez@sfmi-nb-tec113 MINGW64 /vcvrack/Rack-0.5.0/plugins/vcvrack-rtlsdr
$

The Rack screenshots (attached)

rtl-sdr-plugin-rack-screenshot


The Process Monitor screenshots (attached)

rtl-sdr-plugin-pm-screenshot

@dizzisound Ok, it looks like this is broken on Mac too and only worked because of some kind of dylib caching (verified by otool -L ./plugin.dylib ).

I managed to get it to link by passing the absolute paths to the final g++ command - does Windows rtlsdr include a non-DLL version of the library?

c++ -o plugin.dylib build/src/PQ.cpp.o build/src/sdr/SDR.cpp.o build/src/sdr/convenience.c.o build/src/sdr/rtl-sdr.c.o /usr/local/Cellar/libusb/1.0.21/lib/libusb-1.0.a /usr/local/Cellar/librtlsdr/0.5.3/lib/librtlsdr.a -shared -undefined dynamic_lookup -stdlib=libc++ -mmacosx-version-min=10.7

I'm going to investigate how to get the absolute path to a static library.

@wizardishungry Hi Jon, I report what anticipated in the FB discussion group.
I manage to build full-statically the plugin using he makefile you highlighted above. To be precise, I only had to make two small edits to be compliant with my native Windows 8.1 environment.
I post a comment on the makefile edits here:
2d8bad4

Here instead I am posting:

  • the console log from the makefile build launched on my Windows 8.1 machine, that completes successfully
  • the binary release generated from the <make VERSION=0.5.0 dist> command

CONSOLE OUTPUT

danielez@sfmi-nb-tec113 MINGW64 /vcvrack/Rack-0.5.0/plugins/vcvrack-rtlsdr
$ make
Makefile:29: warning: overriding recipe for target 'dist'
../../plugin.mk:36: warning: ignoring old recipe for target 'dist'
g++ -IC:/msys64/mingw64/include/ -IC:/msys64/mingw64/include/libusb-1.0 -I/mingw64/include/libusb-1.0 -fPIC -I../../include -I../../dep/include -MMD -g -O3 -march=nocona -ffast-math -fno-finite-math-only -Wall -Wextra -Wno-unused-parameter -DARCH_WIN -D_USE_MATH_DEFINES  -Wsuggest-override -std=c++11 -c -o build/src/PQ.cpp.o src/PQ.cpp
g++ -IC:/msys64/mingw64/include/ -IC:/msys64/mingw64/include/libusb-1.0 -I/mingw64/include/libusb-1.0 -fPIC -I../../include -I../../dep/include -MMD -g -O3 -march=nocona -ffast-math -fno-finite-math-only -Wall -Wextra -Wno-unused-parameter -DARCH_WIN -D_USE_MATH_DEFINES  -Wsuggest-override -std=c++11 -c -o build/src/sdr/SDR.cpp.o src/sdr/SDR.cpp
cc -IC:/msys64/mingw64/include/ -IC:/msys64/mingw64/include/libusb-1.0 -I/mingw64/include/libusb-1.0 -fPIC -I../../include -I../../dep/include -MMD -g -O3 -march=nocona -ffast-math -fno-finite-math-only -Wall -Wextra -Wno-unused-parameter -DARCH_WIN -D_USE_MATH_DEFINES  -c -o build/src/sdr/convenience.c.o src/sdr/convenience.c
src/sdr/convenience.c:32:0: warning: "_USE_MATH_DEFINES" redefined
 #define _USE_MATH_DEFINES

<command-line>:0:0: note: this is the location of the previous definition
src/sdr/convenience.c: In function 'atofs':
src/sdr/convenience.c:51:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
    suff *= 1e3;
    ~~~~~^~~~~~
src/sdr/convenience.c:52:3: note: here
   case 'm':
   ^~~~
src/sdr/convenience.c:54:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
    suff *= 1e3;
    ~~~~~^~~~~~
src/sdr/convenience.c:55:3: note: here
   case 'k':
   ^~~~
src/sdr/convenience.c: In function 'atoft':
src/sdr/convenience.c:78:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
    suff *= 60;
    ~~~~~^~~~~
src/sdr/convenience.c:79:3: note: here
   case 'm':
   ^~~~
src/sdr/convenience.c:81:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
    suff *= 60;
    ~~~~~^~~~~
src/sdr/convenience.c:82:3: note: here
   case 's':
   ^~~~
cc -IC:/msys64/mingw64/include/ -IC:/msys64/mingw64/include/libusb-1.0 -I/mingw64/include/libusb-1.0 -fPIC -I../../include -I../../dep/include -MMD -g -O3 -march=nocona -ffast-math -fno-finite-math-only -Wall -Wextra -Wno-unused-parameter -DARCH_WIN -D_USE_MATH_DEFINES  -c -o build/src/sdr/rtl-sdr.c.o src/sdr/rtl-sdr.c
src/sdr/rtl-sdr.c:76:0: warning: "_USE_MATH_DEFINES" redefined
 #define _USE_MATH_DEFINES

<command-line>:0:0: note: this is the location of the previous definition
src/sdr/rtl-sdr.c: In function 'polar_disc_lut':
src/sdr/rtl-sdr.c:648:31: warning: left shift of negative value [-Wshift-negative-value]
   return (cj > 0) ? 1<<13 : -1<<13;
                               ^~
src/sdr/rtl-sdr.c: In function 'mark_shared_buffer':
src/sdr/rtl-sdr.c:959:9: warning: statement with no effect [-Wunused-value]
  ss_busy[0];
  ~~~~~~~^~~
src/sdr/rtl-sdr.c: In function 'controller_thread_fn':
src/sdr/rtl-sdr.c:1305:3: warning: implicit declaration of function 'gettimeofday'; did you mean 'mingw_gettimeofday'? [-Wimplicit-function-declaration]
   gettimeofday(&tod, NULL);
   ^~~~~~~~~~~~
   mingw_gettimeofday
src/sdr/rtl-sdr.c: In function 'RtlSdr_init':
src/sdr/rtl-sdr.c:1858:21: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
  radio->rack_buffer = &demod.rack_buffer;
                     ^
src/sdr/rtl-sdr.c:1804:8: warning: unused variable 'freq' [-Wunused-variable]
  char* freq = "99.5M";
        ^~~~
g++ -o plugin.dll build/src/PQ.cpp.o build/src/sdr/SDR.cpp.o build/src/sdr/convenience.c.o build/src/sdr/rtl-sdr.c.o C:/msys64/mingw64/lib/librtlsdr_static.a /mingw64/lib/libusb-1.0.a -shared -L../../ -lRack

danielez@sfmi-nb-tec113 MINGW64 /vcvrack/Rack-0.5.0/plugins/vcvrack-rtlsdr

WIN BETA REELEASE DISTRIBUTABLES

PulsumQuadratum-rtlsdr-0.5.0-win.zip