Reputation: 4114
I want to do a fft in my c++ project, and show it afterwards as an image. In order to do the fft, I am using fftw++, and for displaying the image I wanted to use the CImg-library. Thus I started with the demo project from here. When compiling it, everything works. As soon as I add the CImg-header, it fails with the error
test.cpp: In function ‘int main()’:
test.cpp:18:12: error: ‘f’ was not declared in this scope
Complex *f=ComplexAlign(n);
My file looks like
#include "fftw++.h"
#include "CImg.h"
// Compile with:
// g++ -I .. -fopenmp example0.cc ../fftw++.cc -lfftw3 -lfftw3_omp
//using namespace std;
//using namespace utils;
//using namespace fftwpp;
//using namespace cimg_library;
int main()
{
fftwpp::fftw::maxthreads=get_max_threads();
std::cout << "1D complex to complex in-place FFT, not using the Array class"
<< std::endl;
unsigned int n=4;
Complex *f=utils::ComplexAlign(n);
fftwpp::fft1d Forward(n,-1);
fftwpp::fft1d Backward(n,1);
for(unsigned int i=0; i < n; i++) f[i]=i;
std::cout << "\ninput:" << std::endl;
for(unsigned int i=0; i < n; i++) std::cout << f[i] << std::endl;
Forward.fft(f);
std::cout << "\noutput:" << std::endl;
for(unsigned int i=0; i < n; i++) std::cout << f[i] << std::endl;
Backward.fftNormalized(f);
std::cout << "\ntransformed back:" << std::endl;
for(unsigned int i=0; i < n; i++) std::cout << f[i] << std::endl;
utils::deleteAlign(f);
}
and is compiled with
g++ -I .. -fopenmp test.cpp ../fftw++.cc -lfftw3 -lfftw3_omp
My g++ version is 4.8.5. Adding the Complex.h
-header does not help either. What can I do in order to combine both libraries?
Edit: Further research shows that using the C-library complex.h
and CImg.h
results in a lot of compilation problems, combining the library Complex.h
from the fftw++
-package results also in errors, only the complex
-include from C++ can be used together with the CImg.h
-include file. Reason: Unknown till now.
Upvotes: 1
Views: 256
Reputation: 4114
My solution (even if it is not perfect) is, that I created a second cpp-file:
second.cpp:
#include "CImg.h"
//Code for images
void example(void){
}
and an include-file for that:
second.h:
#ifndef SECOND_H
#define SECOND_H
void example(void);
#endif /* SECOND_H */
If I only include that include file instead of CImg.h
, I can use both fftw++
and CImg
.
Upvotes: 1