Q: 'abs' was not declared in this scope I''m working on GNURadio. Included math.h in my program but still get an error saying that abs was not declared in this scope.
Here is my header file.
#ifndef INCLUDED_SLM_H
#define INCLUDED_SLM_H

#include "candidate_t.h"

namespace gr {
namespace uwspr {
class SLM {
public:
  // returns frequency drift according to the straight line model
  float slmFrequencyDrift(mode_nonlinear m_nl, float cf, float t);
  // generator of trajectory parameters for the straight line model
  bool slmGenerator(mode_nonlinear *m_nl);
  // initialize the generator
  void slmGeneratorInit();
  // index of current instances
  int current;
  SLM(){};
  ~SLM(){};
};
} // namespace uwspr
} // namespace gr
#endif /* INCLUDED_SLM_H */

Here is my code snippet for main function.
#include "slm.h"
#include <math.h>

#ifndef DEBUG
#define DEBUG 1 // set debug mode
#endif
#include "debugmacro.h"

namespace gr {
namespace uwspr {
// Returns frequency drift (in Hz) due to the Doppler effect according to
// the straight line model, described in paper:
float SLM::slmFrequencyDrift(mode_nonlinear m_nl, float cf, float t)
// m_nl = trajectory parameters
// t = time, in seconds
{
  const float c = 1500.0; // sound speed (m/s)
  // sign of velocity vector
  float Sign = (((m_nl.V1 * t + m_nl.p1) * m_nl.V1 +
                 (m_nl.V2 * t + m_nl.p2) * m_nl.V2) > 0) *
                   2 -
               1;
  //
  double numerator = abs(m_nl.V1 * (m_nl.V1 * t + m_nl.p1) +
                         m_nl.V2 * (m_nl.V2 * t + m_nl.p2));
  // norm of connectiong vector (Eq. 16)
  double denominator =
      sqrt(pow(m_nl.V1 * t + m_nl.p1, 2) + pow(m_nl.V2 * t + m_nl.p2, 2));
  if (denominator == 0) {
    return 0.0;
  } else {
    // return -Sign;
    return -Sign * numerator / denominator * cf / c;
  }
}

// Generators of trajectory parameters for the straight line model
bool SLM::slmGenerator(mode_nonlinear *m_nl) {
  // control variables for init velocity
  const double V1_min = -2, V1_max = 2, V1_step = 1;
  const int nV1 = (V1_max - V1_min) / V1_step + 1;
  const double V2_min = -2, V2_max = 2, V2_step = 1;
  const int nV2 = (V2_max - V2_min) / V2_step + 1;
  // control variables for init position on y-axis
  const int p2_min = 50, p2_max = 850, p2_step = 200;
  const int np2 = (p2_max - p2_min) / p2_step + 1;
  // number of generated instances
  const int last = nV1 * nV2 * np2;
  // indices into the instances
  static int ip2, iV1, iV2;
  if (current == 0) {
    ip2 = 0;
    iV1 = 0;
    iV2 = 0;
  }
  if (current < last) { // not generated all instances?
    if (ip2 >= np2) {
      ip2 = 0; // reset index into the list positions
      iV1++;   // next horizontal velocity
      if (iV1 >= nV1) {
        iV1 = 0; // reset index into the list horiz. velocities
        iV2++;   // next vertical velocity
      }
    }
    // map horizontal velocity index to horizontal velocity (m/s)
    m_nl->V1 = iV1 * V1_step + V1_min;
    // map vertical velocity index to vertical velocity (m/s)
    m_nl->V2 = iV2 * V2_step + V2_min;
    // init coordinate on x-axis is always null
    m_nl->p1 = 0;
    // map y-axis coordinate index to y-axis coordinate (m)
    m_nl->p2 = ip2 * p2_step + p2_min;
    ip2++;     // next position on y-axis
    current++; // index of next instance
    return true;
  } else {
    return false; // reach the end
  }
}

void SLM::slmGeneratorInit() { current = 0; }

} /* namespace uwspr */
} /* namespace gr */


A: abs is not defined in <math.h>. It can be found in <stdlib.h> and it is also defined as std::abs in <cmath>.

A: Surprisingly, the abs function is defined in <stdlib.h> rather than <math.h>. (At least, that's the case since C++17). Try including <stdlib.h> or <cstdlib> and see if that fixes things.
Hope this helps!

A: The problem is that you were using the C header file, math.h. The C standard already defined (the global scope) int ::abs(int) to take an int and return an int, and this is defined in stdlib.h. The float version, double ::fabs(double) is defined in math.h, which is the one you need to use.
C++ has overloads, so std::abs has double std::abs(double) and int std::abs(int) overloads. So you could just use the C++ header, cmath, and use std::abs (or std::fabs to prevent conversions) instead.
