dealias/fftwpp

Compilation fails if using CImg in the same project.

Closed this issue · 5 comments

Error:

~/fftw++-2.02/Complex.h:31:7: error: expected identifier before numeric constant
 class Complex
       ^
~/fftw++-2.02/Complex.h:31:7: error: expected unqualified-id before numeric constant

Used compiler: g++-4.8.5 and g++-5.3.0

It sounds like a namespace pollution issue. Can you please post an example?
I downloaded CImg-1.7.1_pre033116 but
grep -r Complex CImg-1.7.1_pre033116
does not indicate anything helpful.

Sample code:

#include "CImg.h"
#include "fftw++.h"
// Compile with:
// g++ -I .. -fopenmp example0.cc ../fftw++.cc -lfftw3 -lfftw3_omp

using namespace std;
using namespace utils;
using namespace fftwpp;

int main()
{
  fftw::maxthreads=get_max_threads();

  cout << "1D complex to complex in-place FFT, not using the Array class"
       << endl;

  unsigned int n=4;
  Complex *f=ComplexAlign(n);

  fft1d Forward(n,-1);
  fft1d Backward(n,1);

  for(unsigned int i=0; i < n; i++) f[i]=i;

  cout << "\ninput:" << endl;
  for(unsigned int i=0; i < n; i++) cout << f[i] << endl;

  Forward.fft(f);

  cout << "\noutput:" << endl;
  for(unsigned int i=0; i < n; i++) cout << f[i] << endl;

  Backward.fftNormalized(f);

  cout << "\ntransformed back:" << endl;
  for(unsigned int i=0; i < n; i++) cout << f[i] << endl;

  deleteAlign(f);
}
If `#include "CImg.h"` is placed before `#include "fftw++.h"`, it results in 
In file included from /usr/include/X11/Xlib.h:44:0,
                 from CImg.h:270,
                 from test.cpp:1:
fftw++-2.02/fftw++.h:77:30: error: expected unqualified-id before numeric constant
 typedef std::complex<double> Complex;
                              ^
fftw++-2.02/align.h:97:8: error: expected unqualified-id before numeric constant
 inline Complex *ComplexAlign(size_t size)
        ^
fftw++-2.02/fftw++.h:93:39: error: expected identifier before numeric constant
 extern "C" fftw_plan Planner(fftw *F, Complex *in, Complex *out);
                                       ^
fftw++-2.02/fftw++.h:93:39: error: expected ‘,’ or ‘...’ before numeric constant
fftw++-2.02/fftw++.h:147:41: error: expected identifier before numeric constant
   unsigned int realsize(unsigned int n, Complex *in, Complex *out=NULL) {
                                         ^
fftw++-2.02/fftw++.h:147:41: error: expected ‘,’ or ‘...’ before numeric constant
fftw++-2.02/fftw++.h:151:41: error: expected identifier before numeric constant
   unsigned int realsize(unsigned int n, Complex *in, double *out) {
                                         ^
fftw++-2.02/fftw++.h:151:41: error: expected ‘,’ or ‘...’ before numeric constant
In file included from test.cpp:2:0:
fftw++-2.02/fftw++.h:151:16: error: ‘unsigned int fftwpp::fftw::realsize(unsigned int, int)’ cannot be overloaded
   unsigned int realsize(unsigned int n, Complex *in, double *out) {
                ^
fftw++-2.02/fftw++.h:147:16: error: with ‘unsigned int fftwpp::fftw::realsize(unsigned int, int)’
   unsigned int realsize(unsigned int n, Complex *in, Complex *out=NULL) {
                ^
In file included from /usr/include/X11/Xlib.h:44:0,
                 from CImg.h:270,
                 from test.cpp:1:
fftw++-2.02/fftw++.h:155:53: error: expected identifier before numeric constant
   unsigned int realsize(unsigned int n, double *in, Complex *out) {
                                                     ^
fftw++-2.02/fftw++.h:155:53: error: expected ‘,’ or ‘...’ before numeric constant
fftw++-2.02/fftw++.h:166:40: error: expected identifier before numeric constant
   static fftw_plan (*planner)(fftw *f, Complex *in, Complex *out);
                                        ^
fftw++-2.02/fftw++.h:166:40: error: expected ‘,’ or ‘...’ before numeric constant
fftw++-2.02/fftw++.h:173:21: error: expected identifier before numeric constant
   static void Shift(Complex *data, unsigned int nx, unsigned int ny,
                     ^
fftw++-2.02/fftw++.h:173:21: error: expected ‘,’ or ‘...’ before numeric constant
fftw++-2.02/fftw++.h:212:21: error: expected identifier before numeric constant
   static void Shift(Complex *data, unsigned int nx, unsigned int ny,
                     ^
fftw++-2.02/fftw++.h:212:21: error: expected ‘,’ or ‘...’ before numeric constant
In file included from test.cpp:2:0:
fftw++-2.02/fftw++.h:212:15: error: ‘static void fftwpp::fftw::Shift(int)’ cannot be overloaded
   static void Shift(Complex *data, unsigned int nx, unsigned int ny,
               ^
fftw++-2.02/fftw++.h:173:15: error: with ‘static void fftwpp::fftw::Shift(int)’
   static void Shift(Complex *data, unsigned int nx, unsigned int ny,
               ^
In file included from /usr/include/X11/Xlib.h:44:0,
                 from CImg.h:270,
                 from test.cpp:1:
fftw++-2.02/fftw++.h:276:26: error: expected identifier before numeric constant
   virtual fftw_plan Plan(Complex *in, Complex *out) {return NULL;};
                          ^
fftw++-2.02/fftw++.h:276:26: error: expected ‘,’ or ‘...’ before numeric constant
fftw++-2.02/fftw++.h:278:26: error: expected identifier before numeric constant
   inline void CheckAlign(Complex *p, const char *s) {
                          ^
fftw++-2.02/fftw++.h:278:26: error: expected ‘,’ or ‘...’ before numeric constant
fftw++-2.02/fftw++.h:296:53: error: expected identifier before numeric constant
   threaddata time(fftw_plan plan1, fftw_plan planT, Complex *in, Complex *out,
                                                     ^
fftw++-2.02/fftw++.h:296:53: error: expected ‘,’ or ‘...’ before numeric constant
fftw++-2.02/fftw++.h:346:10: error: expected unqualified-id before numeric constant
   inline Complex *CheckAlign(Complex *in, Complex *out, bool constructor=true)
          ^
fftw++-2.02/fftw++.h:358:20: error: expected identifier before numeric constant
   threaddata Setup(Complex *in, Complex *out=NULL) {
                    ^
fftw++-2.02/fftw++.h:358:20: error: expected ‘,’ or ‘...’ before numeric constant
fftw++-2.02/fftw++.h:390:20: error: expected identifier before numeric constant
   threaddata Setup(Complex *in, double *out) {
                    ^
fftw++-2.02/fftw++.h:390:20: error: expected ‘,’ or ‘...’ before numeric constant
In file included from test.cpp:2:0:
fftw++-2.02/fftw++.h:390:14: error: ‘fftwpp::threaddata fftwpp::fftw::Setup(int)’ cannot be overloaded
   threaddata Setup(Complex *in, double *out) {
              ^
fftw++-2.02/fftw++.h:358:14: error: with ‘fftwpp::threaddata fftwpp::fftw::Setup(int)’
   threaddata Setup(Complex *in, Complex *out=NULL) {
              ^
In file included from /usr/include/X11/Xlib.h:44:0,
                 from CImg.h:270,
                 from test.cpp:1:
fftw++-2.02/fftw++.h:394:32: error: expected identifier before numeric constant
   threaddata Setup(double *in, Complex *out=NULL) {
                                ^
fftw++-2.02/fftw++.h:394:32: error: expected ‘,’ or ‘...’ before numeric constant
fftw++-2.02/fftw++.h:398:24: error: expected identifier before numeric constant
   virtual void Execute(Complex *in, Complex *out, bool=false) {
                        ^
fftw++-2.02/fftw++.h:398:24: error: expected ‘,’ or ‘...’ before numeric constant
fftw++-2.02/fftw++.h:402:3: error: expected unqualified-id before numeric constant
   Complex *Setout(Complex *in, Complex *out) {
   ^
In file included from test.cpp:2:0:
fftw++-2.02/fftw++.h:440:46: error: expected ‘}’ before end of line
fftw++-2.02/fftw++.h: In member function ‘unsigned int fftwpp::fftw::realsize(unsigned int, int)’:
fftw++-2.02/fftw++.h:148:14: error: ‘out’ was not declared in this scope
     return (!out || in == out) ? 2*(n/2+1) : n;
              ^
fftw++-2.02/fftw++.h:148:21: error: ‘in’ was not declared in this scope
     return (!out || in == out) ? 2*(n/2+1) : n;
                     ^
fftw++-2.02/fftw++.h: In member function ‘unsigned int fftwpp::fftw::realsize(unsigned int, int)’:
fftw++-2.02/fftw++.h:152:23: error: ‘in’ was not declared in this scope
     return realsize(n,in,(Complex *) out);
                       ^
fftw++-2.02/fftw++.h:152:36: error: expected primary-expression before ‘)’ token
     return realsize(n,in,(Complex *) out);
                                    ^
fftw++-2.02/fftw++.h: In member function ‘unsigned int fftwpp::fftw::realsize(unsigned int, double*, int)’:
fftw++-2.02/fftw++.h:156:33: error: expected primary-expression before ‘)’ token
     return realsize(n,(Complex *) in,out);
                                 ^
fftw++-2.02/fftw++.h:156:38: error: ‘out’ was not declared in this scope
     return realsize(n,(Complex *) in,out);
                                      ^
fftw++-2.02/fftw++.h: In static member function ‘static void fftwpp::fftw::Shift(int)’:
fftw++-2.02/fftw++.h:175:22: error: ‘ny’ was not declared in this scope
     unsigned int nyp=ny/2+1;
                      ^
fftw++-2.02/fftw++.h:176:23: error: ‘nx’ was not declared in this scope
     unsigned int stop=nx*nyp;
                       ^
fftw++-2.02/fftw++.h:180:38: error: invalid use of member ‘fftwpp::fftw::threads’ in static member function
 #pragma omp parallel for num_threads(threads)
                                      ^
fftw++-2.02/fftw++.h:137:16: note: declared here
   unsigned int threads;
                ^
fftw++-2.02/fftw++.h:183:18: error: ‘p’ was not declared in this scope
         Complex *p=data+i;
                  ^
fftw++-2.02/fftw++.h:183:20: error: ‘data’ was not declared in this scope
         Complex *p=data+i;
                    ^
fftw++-2.02/fftw++.h: In static member function ‘static void fftwpp::fftw::Shift(int)’:
fftw++-2.02/fftw++.h:214:22: error: ‘nz’ was not declared in this scope
     unsigned int nzp=nz/2+1;
                      ^
fftw++-2.02/fftw++.h:215:23: error: ‘ny’ was not declared in this scope
     unsigned int nyzp=ny*nzp;
                       ^
fftw++-2.02/fftw++.h:216:8: error: ‘nx’ was not declared in this scope
     if(nx % 2 == 0 && ny % 2 == 0) {
        ^
fftw++-2.02/fftw++.h:218:16: error: ‘pstop’ was not declared in this scope
       Complex *pstop=data;
                ^
fftw++-2.02/fftw++.h:218:22: error: ‘data’ was not declared in this scope
       Complex *pstop=data;
                      ^
fftw++-2.02/fftw++.h:219:16: error: ‘p’ was not declared in this scope
       Complex *p=data;
                ^
fftw++-2.02/fftw++.h:221:38: error: invalid use of member ‘fftwpp::fftw::threads’ in static member function
 #pragma omp parallel for num_threads(threads)
                                      ^
fftw++-2.02/fftw++.h:137:16: note: declared here
   unsigned int threads;
                ^
fftw++-2.02/fftw++.h:223:7: error: invalid controlling predicate
       for(unsigned i=0; i < nx; i++) {
       ^
fftw++-2.02/fftw++.h: In member function ‘void fftwpp::fftw::CheckAlign(int)’:
fftw++-2.02/fftw++.h:279:17: error: ‘p’ was not declared in this scope
     if((size_t) p % sizeof(Complex) == 0) return;
                 ^
fftw++-2.02/fftw++.h:280:33: error: ‘s’ was not declared in this scope
     std::cerr << "WARNING: " << s << " array is not " << sizeof(Complex) 
                                 ^
fftw++-2.02/fftw++.h:281:47: error: ‘p’ was not declared in this scope
               << "-byte aligned: address " << p << std::endl;
                                               ^
fftw++-2.02/fftw++.h: In member function ‘fftwpp::threaddata fftwpp::fftw::time(fftw_plan, fftw_plan, int)’:
fftw++-2.02/fftw++.h:302:9: error: ‘in’ was not declared in this scope
     fft(in,out);
         ^
fftw++-2.02/fftw++.h:302:12: error: ‘out’ was not declared in this scope
     fft(in,out);
            ^
fftw++-2.02/fftw++.h:302:15: error: ‘fft’ was not declared in this scope
     fft(in,out);
               ^
fftw++-2.02/fftw++.h:303:12: error: cannot convert ‘fftwpp::fftw::Threads’ from type ‘unsigned int (fftwpp::fftw::)()’ to type ‘unsigned int’
     threads=Threads;
            ^
fftw++-2.02/fftw++.h:314:14: error: cannot convert ‘fftwpp::fftw::Threads’ from type ‘unsigned int (fftwpp::fftw::)()’ to type ‘unsigned int’
       threads=Threads;
              ^
fftw++-2.02/fftw++.h:332:18: error: cannot convert ‘fftwpp::fftw::Threads’ from type ‘unsigned int (fftwpp::fftw::)()’ to type ‘unsigned int’
           threads=Threads;
                  ^
fftw++-2.02/fftw++.h: In member function ‘fftwpp::threaddata fftwpp::fftw::Setup(int)’:
fftw++-2.02/fftw++.h:359:17: error: ‘in’ was not declared in this scope
     bool alloc=!in;
                 ^
fftw++-2.02/fftw++.h:360:18: error: ‘ComplexAlign’ is not a member of ‘utils’
     if(alloc) in=utils::ComplexAlign((doubles+1)/2);
                  ^
fftw++-2.02/fftw++.h:361:5: error: ‘out’ was not declared in this scope
     out=CheckAlign(in,out);
     ^
fftw++-2.02/fftw++.h: In member function ‘fftwpp::threaddata fftwpp::fftw::Setup(int)’:
fftw++-2.02/fftw++.h:391:18: error: ‘in’ was not declared in this scope
     return Setup(in,(Complex *) out);
                  ^
fftw++-2.02/fftw++.h:391:31: error: expected primary-expression before ‘)’ token
     return Setup(in,(Complex *) out);
                               ^
fftw++-2.02/fftw++.h: In member function ‘fftwpp::threaddata fftwpp::fftw::Setup(double*, int)’:
fftw++-2.02/fftw++.h:395:28: error: expected primary-expression before ‘)’ token
     return Setup((Complex *) in,out);
                            ^
fftw++-2.02/fftw++.h:395:33: error: ‘out’ was not declared in this scope
     return Setup((Complex *) in,out);
                                 ^
fftw++-2.02/fftw++.h: In member function ‘virtual void fftwpp::fftw::Execute(int)’:
fftw++-2.02/fftw++.h:399:44: error: ‘in’ was not declared in this scope
     fftw_execute_dft(plan,(fftw_complex *) in,(fftw_complex *) out);
                                            ^
fftw++-2.02/fftw++.h:399:64: error: ‘out’ was not declared in this scope
     fftw_execute_dft(plan,(fftw_complex *) in,(fftw_complex *) out);
                                                                ^
fftw++-2.02/fftw++.h: At global scope:
fftw++-2.02/fftw++.h:440:46: error: expected unqualified-id before end of line
fftw++-2.02/fftw++.h:440:46: error: expected ‘}’ before end of line
fftw++-2.02/fftw++.h:440:46: error: expected declaration before end of line

If placed afterwards, it results in

test.cpp: In function ‘int main()’:
test.cpp:18:12: error: ‘f’ was not declared in this scope
   Complex *f=ComplexAlign(n);
            ^

If completely removed, I get a working compilation. Tested both with g++-4.8.5 and g++-5.3.0

Try inserting
#include "Complex.h"
before
#include "fftw++.h"

If #include "CImg.h" is after the other two:

test.cpp: In function ‘int main()’:
test.cpp:19:12: error: ‘f’ was not declared in this scope
   Complex *f=ComplexAlign(n);
            ^

If before:

In file included from /usr/include/X11/Xlib.h:44:0,
                 from CImg.h:270,
                 from test.cpp:1:
fftw++-2.02/Complex.h:31:7: error: expected identifier before numeric constant
 class Complex
       ^
fftw++-2.02/Complex.h:31:7: error: expected unqualified-id before numeric constant
In file included from test.cpp:3:0:
fftw++-2.02/fftw++.h:180:46: error: expected declaration before end of line

Probably this file is getting included by Cimg.h and the author forgot to #undef Complex at the end.

/usr/include/X11/X.h:#define Complex 0 /* paths may intersect */

The solution is to manually undefine the unwanted preprocessor symbol:

#include "fftw++.h"
#include "CImg.h"
#undef Complex