GCC - expected unqualified identifier before "sizeof" - IT ++ 4.2 in Android NDK

I have successfully created CLAPACK in my Android NDK project. Then I tried to put the IT ++ 4.2 library inside. However, I have some errors that I could not fix. This is what I did in my project:

First I will copy the itpp folder to the jni folder of my project and change the config.h to itpp.

Because I found the isfinite, isinf and isnan function at (place in..android-ndk-r7b \ platform \ android-9 \ arch-arm \ usr \ include). I have set HAVE_DECL_ISINF, HAVE_DECL_ISFINITE and HAVE_DECL_ISNAN to 1.

config.h

#ifndef CONFIG_H
#define CONFIG_H


/* Define to dummy `main' function (if any) required to link to the Fortran
   libraries. */
/* #undef F77_DUMMY_MAIN */

/* Define if F77 and FC dummy `main' functions are identical. */
/* #undef FC_DUMMY_MAIN_EQ_F77 */

/* Define to 1 if you have the `acosh' function. */
#define HAVE_ACOSH 1

/* Define to 1 if you have the `asinh' function. */
#define HAVE_ASINH 1

/* Define to 1 if you have the `atanh' function. */
#define HAVE_ATANH 1

/*#if defined(HAVE_ACML) || defined(HAVE_MKL)
/* Define if you have a BLAS library. */
#define HAVE_BLAS 1
/*#endif

#ifdef HAVE_ACML
/* Define if you have an ACML BLAS library. */
/*#  define HAVE_BLAS_ACML 1
/*#endif

/* Define if you have an ATLAS BLAS library. */
/* #undef HAVE_BLAS_ATLAS */

/*#ifdef HAVE_MKL
/* Define if you have an MKL BLAS library. */
/*#  define HAVE_BLAS_MKL 1
/*#endif

/* Define to 1 if you have the `cbrt' function. */
#  define HAVE_CBRT 1

/* Define to 1 if you have the <cmath> header file. */
/*#define HAVE_CMATH 1

/* Define to 1 if you have the <complex> header file. */
/*#define HAVE_COMPLEX 1

/* Define to 1 if you have the declaration of `isfinite', and to 0 if you
   don't. */
#define HAVE_DECL_ISFINITE 1

/* Define to 1 if you have the declaration of `isinf', and to 0 if you don't.
   */
#define HAVE_DECL_ISINF 1

/* Define to 1 if you have the declaration of `isnan', and to 0 if you don't.
   */
#define HAVE_DECL_ISNAN 1

/* Define to 1 if you have the declaration of `signgam', and to 0 if you
   don't. */
/*#define HAVE_DECL_SIGNGAM 0

/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1

/* Define to 1 if you have the `erf' function. */
#define HAVE_ERF 1

/* Define to 1 if you have the `erfc' function. */
#define HAVE_ERFC 1

/* Define to 1 if you have the `expm1' function. */
/* #undef HAVE_EXPM1 */

/* Define if the compiler supports extern template */
/* #undef HAVE_EXTERN_TEMPLATE */

#if defined(HAVE_ACML) || defined(HAVE_MKL)
/* Define if you have FFT library. */
#  define HAVE_FFT 1
#endif

/* Define if you have FFTW3 library. */
/* #undef HAVE_FFTW3 */

#ifdef HAVE_ACML
/* Define if you have ACML FFT library. */
#  define HAVE_FFT_ACML 1
#endif

#ifdef HAVE_MKL
/* Define if you have MKL FFT library. */
#  define HAVE_FFT_MKL 1
#endif

/* Define to 1 if you have the `finite' function. */
#define HAVE_FINITE 1

/* Define to 1 if you have the `fpclass' function. */
/*#define HAVE_FPCLASS 1

/* Define to 1 if you have the <ieeefp.h> header file. */
/* #undef HAVE_IEEEFP_H */

/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1

/* Define to 1 if you have the `isfinite' function. */
#define HAVE_ISFINITE 1

/* Define to 1 if you have the `isinf' function. */
/* #undef HAVE_ISINF */

/* Define to 1 if you have the `isnan' function. */
/*#define HAVE_ISNAN 1

/*#if defined(HAVE_ACML) || defined(HAVE_MKL)
/* Define if you have LAPACK library. */
#define HAVE_LAPACK 1
/*#endif

/* Define to 1 if you have the `lgamma' function. */
/* #undef HAVE_LGAMMA */

/* Define to 1 if you have the `log1p' function. */
/* #undef HAVE_LOG1P */

/* Define to 1 if you have the `log2' function. */
/* #undef HAVE_LOG2 */

/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1

/* Define to 1 if you have the `rint' function. */
#define HAVE_RINT 1

/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1

/* Define to 1 if you have the `std::isfinite' function. */
/* #undef HAVE_STD_ISFINITE */

/* Define to 1 if you have the `std::isinf' function. */
/* #undef HAVE_STD_ISINF */

/* Define to 1 if you have the `std::isnan' function. */
/* #undef HAVE_STD_ISNAN */

/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1

/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1

/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1

/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1

/* Define to 1 if you have the `tgamma' function. */
/* #undef HAVE_TGAMMA */

/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1

/* Define if you use zdotusub_ Fortran wrapper. */
/* #undef HAVE_ZDOTUSUB */

/* Define if "void zdotu_()" should be used. */
#define HAVE_ZDOTU_VOID 1

/* Define if you want exceptions handling */
/* #undef ITPP_EXCEPTIONS */

/* Name of package */
#define PACKAGE "itpp"

/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "ediap@users.sourceforge.net"

/* Define to the full name of this package. */
#define PACKAGE_NAME "IT++"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "IT++ 4.0.0"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "itpp"

/* Define to the version of this package. */
#define PACKAGE_VERSION "4.0.0"

/* The size of `int', as computed by sizeof. */
#define SIZEOF_INT 4

/* The size of `long', as computed by sizeof. */
#define SIZEOF_LONG 4

/* The size of `long long', as computed by sizeof. */
#define SIZEOF_LONG_LONG 8

/* The size of `short', as computed by sizeof. */
#define SIZEOF_SHORT 2

/* The size of `unsigned int', as computed by sizeof. */
#define SIZEOF_UNSIGNED_INT 4

/* The size of `unsigned long', as computed by sizeof. */
#define SIZEOF_UNSIGNED_LONG 4

/* The size of `unsigned long long', as computed by sizeof. */
#define SIZEOF_UNSIGNED_LONG_LONG 8

/* The size of `unsigned short', as computed by sizeof. */
#define SIZEOF_UNSIGNED_SHORT 2

/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1

/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
/* #undef TIME_WITH_SYS_TIME */

/* Version number of package */
#define VERSION "4.0.0"


#if defined(HAVE_CMATH)
#  include <cmath>
#endif
/*#include <math.h>*/
#endif /* #ifndef CONFIG_H */

      

math.h

   [..]
    #define fpclassify(x) \
    ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
    : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
    : __fpclassifyl(x))

#define isfinite(x)                 \
    ((sizeof (x) == sizeof (float)) ? __isfinitef(x)    \
    : (sizeof (x) == sizeof (double)) ? __isfinite(x)   \
    : __isfinitel(x))
#define isinf(x)                    \
    ((sizeof (x) == sizeof (float)) ? __isinff(x)   \
    : (sizeof (x) == sizeof (double)) ? __isinf(x)  \
    : __isinfl(x))
#define isnan(x)                    \
    ((sizeof (x) == sizeof (float)) ? isnanf(x)     \
    : (sizeof (x) == sizeof (double)) ? isnan(x)    \
    : __isnanl(x))
#define isnormal(x)                 \
    ((sizeof (x) == sizeof (float)) ? __isnormalf(x)    \
    : (sizeof (x) == sizeof (double)) ? __isnormal(x)   \
    : __isnormall(x))
[..]

      

However, when I compile itpp I got an error in itcompat.h file

#ifndef ITCOMPAT_H
#define ITCOMPAT_H

#ifndef _MSC_VER
#  include <itpp/config.h>
#else
#  include <itpp/config_msvc.h>
#endif

//! \cond

// Microsoft Visual C++ underscore prefixed functions
#if defined(_MSC_VER)
#  include <cfloat>
#  define finite(x) _finite(x)
#  define isfinite(x) _finite(x)
#  define isnan(x) _isnan(x)
#  define fpclass(x) _fpclass(x)
#  define FP_NINF _FPCLASS_NINF
#  define FP_PINF _FPCLASS_PINF
#  define jn(a, b) _jn(a, b)
#  define yn(a, b) _yn(a, b)
#  define j0(a) _j0(a)
#  define j1(a) _j1(a)
#endif // defined(_MSC_VER)


// Solaris uses <ieeefp.h> for declaring isnan() and finite() functions
#if defined(HAVE_IEEEFP_H)
#  include <ieeefp.h>
#endif

// These definitions would collide with IT++ functions
#if defined(min)
#  undef min
#endif
#if defined(max)
#  undef max
#endif
#if defined(log2)
#  undef log2
#endif
namespace std
{

#ifndef HAVE_STD_ISINF
#if (HAVE_DECL_ISINF == 1) || defined(HAVE_ISINF)
inline int isinf(double x) { return ::isinf(x); } //line 77
#elif defined(FPCLASS)
inline int isinf(double x)
{
  if (::fpclass(a) == FP_NINF) return -1;
  else if (::fpclass(a) == FP_PINF) return 1;
  else return 0;
}
#else
inline int isinf(double x)
{
  if ((x == x) && ((x - x) != 0.0)) return (x < 0.0 ? -1 : 1);
  else return 0;
}
#endif // #if (HAVE_DECL_ISINF == 1) || defined(HAVE_ISINF)
#endif // #ifndef HAVE_STD_ISINF

#ifndef HAVE_STD_ISNAN
#if (HAVE_DECL_ISNAN == 1) || defined(HAVE_ISNAN)
inline int isnan(double x) { return ::isnan(x); }   //line 96
#else
inline int isnan(double x) { return ((x != x) ? 1 : 0); }
#endif // #if (HAVE_DECL_ISNAN == 1) || defined(HAVE_ISNAN)
#endif // #ifndef HAVE_STD_ISNAN

#ifndef HAVE_STD_ISFINITE
#if (HAVE_DECL_ISFINITE == 1) || defined(HAVE_ISFINITE)
inline int isfinite(double x) { return ::isfinite(x); }   //line 104
#elif defined(HAVE_FINITE)
inline int isfinite(double x) { return ::finite(x); }
#else
inline int isfinite(double x)
{
  return ((!std::isnan(x) && !std::isinf(x)) ? 1 : 0);
}
#endif // #if (HAVE_DECL_ISFINITE == 1) || defined(HAVE_ISFINITE)
#endif // #ifndef HAVE_STD_ISFINITE

} // namespace std

[..]

      

converter.cpp

#include <itpp/base/converters.h>
#include <itpp/base/itcompat.h>
#include <itpp/base/matfunc.h>
#include <itpp/base/math/log_exp.h>

//! \cond

namespace itpp
{

// ----------------------------------------------------------------------
// Vector converters
// ----------------------------------------------------------------------

ivec to_ivec(int s) { ivec out(1); out(0) = s; return out; }

vec to_vec(double s) { vec out(1); out(0) = s; return out; }

cvec to_cvec(double real, double imag)
{
  cvec out(1);
  out(0) = std::complex<double>(real, imag);
  return out;
}

// ----------------------------------------------------------------------
// Miscellaneous converters
// ----------------------------------------------------------------------

bvec dec2bin(int length, int index)
{
  int i, bintemp = index;
  bvec temp(length);

  for (i = length - 1; i >= 0; i--) {
    temp(i) = bin(bintemp & 1);
    bintemp = (bintemp >> 1);
  }
  return temp;
}

bvec dec2bin(int index, bool msb_first)
{
  int length = int2bits(index);
  int i, bintemp = index;
  bvec temp(length);

  for (i = length - 1; i >= 0; i--) {
    temp(i) = bin(bintemp & 1);
    bintemp = (bintemp >> 1);
  }
  if (msb_first) {
    return temp;
  }
  else {
    return reverse(temp);
  }
}

void dec2bin(int index, bvec &v)
{
  int i, bintemp = index;
  v.set_size(int2bits(index), false);

  for (i = v.size() - 1; i >= 0; i--) {
    v(i) = bin(bintemp & 1);
    bintemp = (bintemp >> 1);
  }
}

int bin2dec(const bvec &inbvec, bool msb_first)
{
  int i, temp = 0;
  int sizebvec = inbvec.length();
  if (msb_first) {
    for (i = 0; i < sizebvec; i++) {
      temp += pow2i(sizebvec - i - 1) * int(inbvec(i));
    }
  }
  else {
    for (i = 0; i < sizebvec; i++) {
      temp += pow2i(i) * int(inbvec(i));
    }
  }
  return temp;
}

bvec oct2bin(const ivec &octalindex, short keepzeros)
{
  int length = octalindex.length(), i;
  bvec out(3*length);
  for (i = 0; i < length; i++) {
    out.replace_mid(3*i, dec2bin(3, octalindex(i)));
  }
  //remove zeros if keepzeros = 0
  if (keepzeros == 0) {
    for (i = 0; i < out.length(); i++) {
      if ((short)out(i) != 0) {
        return out.right(out.length() - i);
        break;
      }
    }
    return bvec("0");
  }
  else {
    return out;
  }
}

ivec bin2oct(const bvec &inbits)
{
  int start, Itterations = ceil_i(inbits.length() / 3.0);
  ivec out(Itterations);
  for (int i = Itterations - 1; i > 0; i--) {
    start = 3 * i - (3 * Itterations - inbits.length());
    out(i) = bin2dec(inbits.mid(start, 3));
  }
  out(0) = bin2dec(inbits.left(inbits.length() - ((Itterations - 1) * 3)));
  return out;
}

ivec bin2pol(const bvec &inbvec)
{
  return 1 -2*to_ivec(inbvec);
}

bvec pol2bin(const ivec &inpol)
{
  return to_bvec((1 -inpol) / 2);
}


// Round to nearest integer, return result in double
double round(double x) { return ::rint(x); }
// Round to nearest integer
vec round(const vec &x) { return apply_function<double>(::rint, x); }
// Round to nearest integer
mat round(const mat &x) { return apply_function<double>(::rint, x); }
// Round to nearest integer
int round_i(double x) { return static_cast<int>(::rint(x)); }

// Round to nearest integer and return ivec
ivec round_i(const vec &x) { return to_ivec(round(x)); }
// Round to nearest integer and return imat
imat round_i(const mat &x) { return to_imat(round(x)); }

// Round to nearest upper integer
ivec ceil_i(const vec &x) { return to_ivec(ceil(x)); }
// Round to nearest upper integer
imat ceil_i(const mat &x) { return to_imat(ceil(x)); }

// Round to nearest lower integer
ivec floor_i(const vec &x) { return to_ivec(floor(x)); }
// Round to nearest lower integer
imat floor_i(const mat &x) { return to_imat(floor(x)); }


cvec round_to_zero(const cvec &x, double threshold)
{
  cvec temp(x.length());

  for (int i = 0; i < x.length(); i++)
    temp(i) = round_to_zero(x(i), threshold);

  return temp;
}

cmat round_to_zero(const cmat &x, double threshold)
{
  cmat temp(x.rows(), x.cols());

  for (int i = 0; i < x.rows(); i++) {
    for (int j = 0; j < x.cols(); j++) {
      temp(i, j) = round_to_zero(x(i, j), threshold);
    }
  }

  return temp;
}

cvec round_to_infty(const cvec &in, const double threshold)
{
  cvec temp(in.length());

  for (int i = 0; i < in.length(); i++)
    temp(i) = round_to_infty(in(i), threshold);

  return temp;
}

cmat round_to_infty(const cmat &in, const double threshold)
{
  cmat temp(in.rows(), in.cols());

  for (int i = 0; i < in.rows(); i++) {
    for (int j = 0; j < in.cols(); j++) {
      temp(i, j) = round_to_infty(in(i, j), threshold);
    }
  }

  return temp;
}

std::string to_str(const double &i, const int precision)
{
  std::ostringstream ss;
  ss.precision(precision);
  ss.setf(std::ostringstream::scientific, std::ostringstream::floatfield);
  ss << i;
  return ss.str();
}

// ----------------------------------------------------------------------
// Instantiations
// ----------------------------------------------------------------------

template bvec to_bvec(const svec &v);
template bvec to_bvec(const ivec &v);

template svec to_svec(const bvec &v);
template svec to_svec(const ivec &v);
template svec to_svec(const vec &v);

template ivec to_ivec(const bvec &v);
template ivec to_ivec(const svec &v);
template ivec to_ivec(const vec &v);

template vec to_vec(const bvec &v);
template vec to_vec(const svec &v);
template vec to_vec(const ivec &v);

template cvec to_cvec(const bvec &v);
template cvec to_cvec(const svec &v);
template cvec to_cvec(const ivec &v);
template cvec to_cvec(const vec &v);

template cvec to_cvec(const bvec &real, const bvec &imag);
template cvec to_cvec(const svec &real, const svec &imag);
template cvec to_cvec(const ivec &real, const ivec &imag);
template cvec to_cvec(const vec &real, const vec &imag);

template bmat to_bmat(const smat &m);
template bmat to_bmat(const imat &m);

template smat to_smat(const bmat &m);
template smat to_smat(const imat &m);
template smat to_smat(const mat &m);

template imat to_imat(const bmat &m);
template imat to_imat(const smat &m);
template imat to_imat(const mat &m);

template mat to_mat(const bmat &m);
template mat to_mat(const smat &m);
template mat to_mat(const imat &m);

template cmat to_cmat(const bmat &m);
template cmat to_cmat(const smat &m);
template cmat to_cmat(const imat &m);
template cmat to_cmat(const mat &m);

template cmat to_cmat(const bmat &real, const bmat &imag);
template cmat to_cmat(const smat &real, const smat &imag);
template cmat to_cmat(const imat &real, const imat &imag);
template cmat to_cmat(const mat &real, const mat &imag);

} // namespace itpp

//! \endcond

      

Console output:

Compile++ arm    : itpp <= converters.cpp

In file included from E:/hello-jni/jni/itpp/base/converters.cpp:30:0:
E:/hello-jni/jni/itpp/base/itcompat.h:77:12: error: expected unqualified-id before 'sizeof'
E:/hello-jni/jni/itpp/base/itcompat.h:77:12: error: expected ')' before 'sizeof'
E:/hello-jni/jni/itpp/base/itcompat.h:77:12: error: expected ')' before 'sizeof'
E:/hello-jni/jni/itpp/base/itcompat.h:96:12: error: expected unqualified-id before 'sizeof'
E:/hello-jni/jni/itpp/base/itcompat.h:96:12: error: expected ')' before 'sizeof'
E:/hello-jni/jni/itpp/base/itcompat.h:96:12: error: expected ')' before 'sizeof'
E:/hello-jni/jni/itpp/base/itcompat.h:104:12: error: expected unqualified-id before 'sizeof'
E:/hello-jni/jni/itpp/base/itcompat.h:104:12: error: expected ')' before 'sizeof'
E:/hello-jni/jni/itpp/base/itcompat.h:104:12: error: expected ')' before 'sizeof'
/cygdrive/e/Soft/android-ndk-r7b/build/core/build-binary.mk:249: recipe for target `obj/local/armeabi-v7a/objs-debug/itpp/itpp/base/converters.o' failed
make: *** [obj/local/armeabi-v7a/objs-debug/itpp/itpp/base/converters.o] Error 1

      

Could you please give me some advice on my problem? I am new to android-ndk. Thank you so much for your help!

+3


source to share


1 answer


The reason is because you isinf

define it as a macro. Later, you try to define a function with that name.

You should notice that macros expand while the lexer is running (or even skipping before). This means that it expands macros without understanding the correctness of the parsing, let alone the context. This is why even though you are declaring a function in a namespace, lexer does not understand it and still accepts the function name as a macro.



To get around this, you need to make sure itcompat.h doesn't define it isinf

. The appearance of the header file must be determined HAVE_STD_ISINF

. Not enough HAVE_DECL_ISINF

as it is isinf

still declared in itcompat.h in this case . I guess if you include math.h

before itcompat.h it will figure it out HAVE_STD_ISINF

.

+2


source







All Articles