Dear Friends,
I am having problems with linking my *.cc file with another library file. I have asigned the path in the Makefile but its not working and giving errors while doing 'make'. I am a newbee in C++ programing and am trying to modify a program written by somebody else. Kindly help me in debugging.
Thanks in advance.
Sankar
This is the Makefile and below is the error message
Makefile :-
[calphy@lin07 analysis]$ make
g++ -I/scratch/tmp1/tmp/calphy/KER_05082005/fftw/include -Wall -fPIC -O3 -o find_instr find_instr.cc -L/scratch/tmp1/tmp/calphy/KER_05082005/fftw/lib -lmffm -lfft -l2Dfft -lfftw3
/tmp/ccXeD1pe.o(.text+0x889): In function `main':
: undefined reference to `complexFFTData::complexFFTData[in-charge](int)'
/tmp/ccXeD1pe.o(.text+0x8a3): In function `main':
: undefined reference to `complexFFT::complexFFT[in-charge](complexFFTData*)'
/tmp/ccXeD1pe.o(.text+0x8bd): In function `main':
: undefined reference to `complexFFTData::complexFFTData[in-charge](int)'
/tmp/ccXeD1pe.o(.text+0x8d7): In function `main':
: undefined reference to `complexFFT::complexFFT[in-charge](complexFFTData*)'
/tmp/ccXeD1pe.o(.text+0x8f1): In function `main':
: undefined reference to `complexFFTData::complexFFTData[in-charge](int)'
/tmp/ccXeD1pe.o(.text+0x90b): In function `main':
: undefined reference to `complexFFT::complexFFT[in-charge](complexFFTData*)'
/tmp/ccXeD1pe.o(.text+0xa82): In function `main':
: undefined reference to `complexFFT::fwdTransform()'
/tmp/ccXeD1pe.o(.text+0xa8e): In function `main':
: undefined reference to `complexFFT::fwdTransform()'
/tmp/ccXeD1pe.o(.text+0xb30): In function `main':
: undefined reference to `complexFFT::invTransform()'
/tmp/ccXeD1pe.o(.text+0xcf1): In function `main':
: undefined reference to `complexFFT::~complexFFT [in-charge]()'
/tmp/ccXeD1pe.o(.text+0xcfd): In function `main':
: undefined reference to `complexFFTData::~complexFFTData [in-charge]()'
/tmp/ccXeD1pe.o(.text+0xd09): In function `main':
: undefined reference to `complexFFT::~complexFFT [in-charge]()'
/tmp/ccXeD1pe.o(.text+0xd15): In function `main':
: undefined reference to `complexFFTData::~complexFFTData [in-charge]()'
/tmp/ccXeD1pe.o(.text+0xd21): In function `main':
: undefined reference to `complexFFT::~complexFFT [in-charge]()'
/tmp/ccXeD1pe.o(.text+0xd2d): In function `main':
: undefined reference to `complexFFTData::~complexFFTData [in-charge]()'
/tmp/ccXeD1pe.o(.text+0x1a88): In function `main':
: undefined reference to `complexFFT::~complexFFT [in-charge]()'
/tmp/ccXeD1pe.o(.text+0x1a99): In function `main':
: undefined reference to `complexFFTData::~complexFFTData [in-charge]()'
/tmp/ccXeD1pe.o(.text+0x1aaa): In function `main':
: undefined reference to `complexFFT::~complexFFT [in-charge]()'
/tmp/ccXeD1pe.o(.text+0x1abb): In function `main':
: undefined reference to `complexFFTData::~complexFFTData [in-charge]()'
/tmp/ccXeD1pe.o(.text+0x1acc): In function `main':
: undefined reference to `complexFFT::~complexFFT [in-charge]()'
/tmp/ccXeD1pe.o(.text+0x1add): In function `main':
: undefined reference to `complexFFTData::~complexFFTData [in-charge]()'
collect2: ld returned 1 exit status
make: *** [find_instr] Error 1
08-10-2005, 03:25 AM
Danny
It looks like the linkage type of certain identifiers in your program is wrong. Check the relevant library's header file and see whether it contains an
extern "C"
{
//..declarations
}
declaration. Make sure that the function protypes you're using in yoru program are in sync with how they are defined in the library. In other words, I suspect that your program's headers don't have this extern "C" declaration.
08-10-2005, 04:38 AM
sankar_de
Dear Danny,
I didn't find anything like 'extern "C" declaration' or may be I didn't understand what you said. I actually have an experimental spectrum. I want to find out the true spectrum by deconvolution method using an instrumentation function. So I am using the FFT. I am sending you the main 'find_instr.cc' file and complexFFT.H. They are quite big. I think they will be helpful.
Thanks,
Sankar
complexFFT.H :-
/* Copyright 2001,2002 Matt Flax <flatmax@ieee.org>
This file is part of the MFFM FFTw Wrapper library.
MFFM MFFM FFTw Wrapper library is free software; you can
redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
MFFM FFTw Wrapper library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You have received a copy of the GNU General Public License
along with the MFFM FFTw Wrapper library
*/
#ifndef COMPLEXFFT_H_
#define COMPLEXFFT_H_
/// class complexFFTData controls and manipulates complex fft data
class complexFFTData {
public:
/// Specifies the size of the data array
int size;
/// the input and output arrays
fftw_complex *in, *out;
/// the power_spectrum array
fftw_real *power_spectrum;
/// The total power (summed) of the power spectrum as used in the method compPowerSpec
double totalPower;
/// Constructor with all memory to be allocated internally
complexFFTData(int sz);
/// Deconstructor
~complexFFTData(void);
/// Use this to change associated fft data (for fft'ing)
void switchData(complexFFTData *d);
/// Limits the maximum to 'lim' and returns the last fft bin with max
int limitHalfPowerSpec(double lim);
/// Returns the number of elements in the input and output arrays
int getSize(){return size;}
// int getHalfSize(){ if (!(size%2)) return size/2; else return size/2+1;}
/// This function computes the power spectrum and returns the max bin
int compPowerSpec();
// int powerSpecDeriv(); // Find the derivative of the power spectrum
};
///class complexFFT controls fftw plans and executes fwd/inv transforms
class complexFFT {
/// The fwd/inv plans
fftw_plan fwdPlan, invPlan;
/// Method to create the plans
void createPlan(void);
/// Method to destroy the plans
void destroyPlan(void);
protected:
// int size;
/// The pointer to the relevant data
complexFFTData *data;
public:
// complexFFT(int sz, char *ws=NULL);
/// fft init ... data pointed to by 'd'
complexFFT(complexFFTData *d);
/// fft deconstructor
~complexFFT();
/// Use this to change associated fft data (for fft'ing)
void switchData(complexFFTData *d);
/// Forward transform the data (in to out)
void fwdTransform(); // Forward fft
/// Inverse transform the data (out to in)
void invTransform(); // Inverse fft
};
/** \example complexFFTExample.cc
* This is an example of how to use the class.
*/
#endif // COMPLEXFFT_H_
find_instr.cc :-
// Given spectrum and simulation find instrumentation function
int main (void){
ifstream spectrum(SPECFILE);
ifstream simulation(SIMFILE);
ofstream output(OUTPUTFILE);
ofstream output1(OUTPUTFILE1);
ofstream output2(OUTPUTFILE2);
int count_spec=0, count_sim=0;
double var;
double x,y,u,v, x1,y1, temp;
// Get the file size and check file exists ....
if (!spectrum){
cout <<"input spectrum not opened !"<<endl;
exit(-1);
}
if (!simulation){
cout <<"input simulation not opened !"<<endl;
exit(-1);
}
while (spectrum >> var)
count_spec++;
while (simulation >> var)
count_sim++;
cout<<count_spec<<" variables in file "<<SPECFILE<<endl;
cout<<count_sim <<" variables in file "<<SIMFILE<<endl;
OK, so it's not an extern "C" problem. The problem is simpler: the linker doesn't find the definitions of the member functions you're calling. The most liekly cause is that the linker doesn't look for it in the right places.
08-10-2005, 06:01 AM
sankar_de
Dear Danny,
I have my complexFFT.H file in the include directory whose path I am defining in the Makefile for find_instr.cc to link to the required header files but still its showing me errors. So where I am wrong.
The erros you're getting are generated by the linker. This means that the ld command probably doesn't contain the correct libraries. It's not a compiler flag.