library linking problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: library linking problem

  1. #1
    Join Date
    Aug 2005
    Posts
    3

    library linking problem

    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 :-

    FFTWDIR = /scratch/tmp1/tmp/calphy/KER_05082005/fftw
    CPPFLAGS += -I$(FFTWDIR)/include -Wall -fPIC
    LDFLAGS += -L$(FFTWDIR)/lib -lmffm -lfft -l2Dfft -lfftw3

    all: find_instr

    instr: instr.cc
    g++ $(CPPFLAGS) -O3 -o $@ $^ $(LDFLAGS)

    find_instr: find_instr.cc
    g++ $(CPPFLAGS) -O3 -o $@ $^ $(LDFLAGS)


    clean:
    rm -f a.out cfft instr


    ERROR MESSAGE :-

    [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

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    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.
    Danny Kalev

  3. #3
    Join Date
    Aug 2005
    Posts
    3
    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_

    #include <fftw3.h>

    #ifndef fftw_real
    #define fftw_real double
    #endif
    #define c_re(c) ((c)[0])
    #define c_im(c) ((c)[1])

    #include <iomanip>
    using namespace std;

    #define PLANTYPE FFTW_ESTIMATE

    /// 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


    #include <fstream>
    #include <iomanip>
    #include <iostream>

    //#include <realFFT.H>
    #include "complexFFT.H"
    #include <stdlib.h>
    #define SPECFILE "Ar2+_pure_expt_norm_spec.dat"
    #define SIMFILE "Ar2+_sim_norm_spec.dat"
    #define OUTPUTFILE "instr_pow.dat"
    #define OUTPUTFILE1 "instr_real.txt"
    #define OUTPUTFILE2 "instr_imag.txt"

    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;

    if(count_spec!=count_sim) {
    cout<< "Unequal input files !"<< endl;
    exit(-1);
    }


    spectrum.clear();
    spectrum.seekg(0);

    simulation.clear();
    simulation.seekg(0);

    // realFFTData fftData(count);
    // realFFT rfft(&fftData);

    complexFFTData specData(count_spec);
    complexFFT specfft(&specData);

    complexFFTData simData(count_sim);
    complexFFT simfft(&simData);

    complexFFTData outData(count_spec);
    complexFFT outfft(&outData);

    // read data into data and rdata :
    for (int i=0; i<count_spec; i++){
    spectrum >> c_re(specData.in[i]);
    c_im(specData.in[i])=0;
    }
    spectrum.close();

    for(int i=0;i<count_sim;i++){
    simulation >> c_re(simData.in[i]);
    c_im(simData.in[i])=0;
    }
    simulation.close();


    // forward transform :
    specfft.fwdTransform();
    //
    //instfft.fwdTransform();
    simfft.fwdTransform();

    for(int i=0;i<count_sim;i++){
    x= c_re(specData.out[i]);
    y= c_im(specData.out[i]);
    u= c_re(simData.out[i]);
    v= c_im(simData.out[i]);

    temp= u*u+v*v;
    x1 = (x*u+y*v)/temp;
    y1 = (y*u-x*v)/temp;

    c_re(outData.in[i]) = x1;
    c_im(outData.in[i]) = y1;
    }
    //inverse transform
    //outfft.invTransform();





    // Find the power spectrum ...
    //fftData.compPowerSpec();

    // inverse transform to check what happens (have to rescale too):
    outfft.invTransform();

    // output to file :
    //for (int i=0; i<(count+1)/2; i++){
    // output << fftData.power_spectrum[i]<<'\n';
    //}
    // cout <<(count+1)/2<<endl;
    //output.close();

    for (int i=0; i<count_sim; i++){
    output1 << c_re(outData.in[i]) <<'\n';
    output2 << c_im(outData.in[i]) <<'\n';

    output << c_re(outData.out[i]) << " " << c_im(outData.out[i]) << endl;
    }
    output.close();
    output1.close();
    output2.close();
    return 0;
    }

  4. #4
    Join Date
    Nov 2003
    Posts
    4,118
    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.
    Danny Kalev

  5. #5
    Join Date
    Aug 2005
    Posts
    3
    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.

    Regards,
    Sankar


    [calphy@lin07 include]$ ls
    complexFFT.H fftw3.f fftw3.h real2DFFT.H realFFTData.H realFFT.H
    [calphy@lin07 include]$ pwd
    /scratch/tmp1/tmp/calphy/KER_05082005/fftw/include
    [calphy@lin07 include]$

  6. #6
    Join Date
    Nov 2003
    Posts
    4,118
    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.
    Danny Kalev

Similar Threads

  1. Replies: 1
    Last Post: 09-05-2002, 10:01 AM
  2. Bring Your User Interface to the Printed Page with the XtraPrinting Library
    By Developer Express in forum dotnet.announcements
    Replies: 0
    Last Post: 03-21-2002, 08:03 PM
  3. Replies: 0
    Last Post: 12-13-2001, 01:06 PM
  4. Replies: 0
    Last Post: 10-06-2001, 03:43 PM
  5. Replies: 0
    Last Post: 06-23-2000, 03:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center