CImg 和 fftw++ 的组合失败
Combination of CImg and fftw++ fails
我想在我的 C++ 项目中做一个 fft,然后将它显示为图像。为了进行 fft,我使用了 fftw++,为了显示图像,我想使用 CImg 库。因此,我从 here 的演示项目开始。编译时,一切正常。一旦我添加 CImg-header,它就会失败并显示错误
test.cpp: In function ‘int main()’:
test.cpp:18:12: error: ‘f’ was not declared in this scope
Complex *f=ComplexAlign(n);
我的文件看起来像
#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);
}
并使用
编译
g++ -I .. -fopenmp test.cpp ../fftw++.cc -lfftw3 -lfftw3_omp
我的g++版本是4.8.5。添加 Complex.h
-header 也无济于事。我该怎么做才能合并这两个库?
编辑:进一步的研究表明,使用 C 库 complex.h
和 CImg.h
会导致很多编译问题,结合 fftw++
中的库 Complex.h
-package 也会导致错误,只有 C++ 中的 complex
-include 可以与 CImg.h
-include 文件一起使用。原因:目前未知。
我的解决方案(即使它并不完美)是,我创建了第二个 cpp 文件:
second.cpp:
#include "CImg.h"
//Code for images
void example(void){
}
和一个包含文件:
second.h:
#ifndef SECOND_H
#define SECOND_H
void example(void);
#endif /* SECOND_H */
如果我只包含那个包含文件而不是 CImg.h
,我可以同时使用 fftw++
和 CImg
。
我想在我的 C++ 项目中做一个 fft,然后将它显示为图像。为了进行 fft,我使用了 fftw++,为了显示图像,我想使用 CImg 库。因此,我从 here 的演示项目开始。编译时,一切正常。一旦我添加 CImg-header,它就会失败并显示错误
test.cpp: In function ‘int main()’:
test.cpp:18:12: error: ‘f’ was not declared in this scope
Complex *f=ComplexAlign(n);
我的文件看起来像
#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);
}
并使用
编译g++ -I .. -fopenmp test.cpp ../fftw++.cc -lfftw3 -lfftw3_omp
我的g++版本是4.8.5。添加 Complex.h
-header 也无济于事。我该怎么做才能合并这两个库?
编辑:进一步的研究表明,使用 C 库 complex.h
和 CImg.h
会导致很多编译问题,结合 fftw++
中的库 Complex.h
-package 也会导致错误,只有 C++ 中的 complex
-include 可以与 CImg.h
-include 文件一起使用。原因:目前未知。
我的解决方案(即使它并不完美)是,我创建了第二个 cpp 文件:
second.cpp:
#include "CImg.h"
//Code for images
void example(void){
}
和一个包含文件:
second.h:
#ifndef SECOND_H
#define SECOND_H
void example(void);
#endif /* SECOND_H */
如果我只包含那个包含文件而不是 CImg.h
,我可以同时使用 fftw++
和 CImg
。