cjcliffe / CubicSDR

Cross-Platform Software-Defined Radio Application
http://www.cubicsdr.com
GNU General Public License v2.0
2.02k stars 249 forks source link

Hamlib broke compilation of 'rig/RigThread.cpp' #1020

Open gvanem opened 6 months ago

gvanem commented 6 months ago

A recent commit in Hamlib, broke the compilation of rig/RigThread.cpp:

rig/RigThread.cpp(28): error C2664: 'int rig_list_foreach(int (__cdecl *)(rig_caps *,void *),void *)': 
cannot convert argument 1 from 'int (__cdecl *)(const rig_caps *,void *)' to 'int (__cdecl *)(rig_caps *,void *)'
rig/RigThread.cpp(28): note: None of the functions with this name in scope match the target type

But now Hamlib has also a #define RIGCAPS_NOT_CONST to test for.

This is how I hacked around this issue:

--- a/rig/RigThread.cpp 2023-06-01 06:15:02
+++ b/rig/RigThread.cpp 2023-12-12 17:45:41
@@ -32,7 +32,7 @@
     return RigThread::rigCaps;
 }

-int RigThread::add_hamlib_rig(const struct rig_caps *rc, void* /* f */)
+int RigThread::add_hamlib_rig(HAMLIB_RIG_CAPS *rc, void* /* f */)
 {
     rigCaps.push_back(rc);
     return 1;

--- a/rig/RigThread.h 2023-06-01 06:15:02
+++ b/rig/RigThread.h 2023-12-12 17:45:34
@@ -12,6 +12,18 @@
        #define FILPATHLEN HAMLIB_FILPATHLEN
 #endif

+#ifdef RIGCAPS_NOT_CONST
+
+  /* Since this commit:
+   *   https://github.com/Hamlib/Hamlib/commit/ed941939359da9f8734dbdf4a21a9b01622a1a6e
+   * a 'struct rig_caps' is no longer constant (as passed to 'rig_list_foreach()' etc.).
+   */
+
+  #define HAMLIB_RIG_CAPS struct rig_caps
+#else
+  #define HAMLIB_RIG_CAPS const struct rig_caps
+#endif
+
 struct rigGreater
 {
     bool operator()( const struct rig_caps *lx, const struct rig_caps *rx ) const {
@@ -50,7 +62,7 @@
     std::string getErrorMessage();

     static RigList &enumerate();
-    static int add_hamlib_rig(const struct rig_caps *rc, void* f);
+    static int add_hamlib_rig(HAMLIB_RIG_CAPS *rc, void* f);

 protected:
     void setErrorStateFromHamlibCode(int errcode);

I'm on Win-10 using MSVC (x64).