compile error - undefined reference

What are the possible reasons that the following code would give the compile error below:


1
2
3
4
5
6
7
8
9
//Create a system for each channel &
//copy propogated field inorder
//to demultipelx the channels
  
System C_wdm[(channels)];
  for (int i=0;i<(channels);i++){
  cp_ptr[i] = new Field((field_win*2),field_win);
  *cp_ptr[i] = field;
  }



Output is:

Main.o(.text+0x10d9): In function `main':
/home/frenchcr/src/mdwdm/Main.cc:202: undefined reference to `Field::operator=(Field const&)'
collect2: ld returned 1 exit status
make: *** [Main] Error 1



??
Last edited on
You declared an operator = for Field class, but you did not define it.
thanks, im new-ish can you help with syntax.
You probably forgot to link wherever that Field class is defined to the rest of your program. Is that Field class from a library, or did you write it yourself?

Im sure its a problem with this Main.cc file and not the library (yes, Field is a class in my library). I just tried another Main.cc that i wrote for some other purpose, it also uses the Field class and it compiled and ran fine.

line number 8 in the code snippet above is where the compiler has the problem, i.e. around this part

cp_ptr[i] = new Field((field_win*2),field_win);
*cp_ptr[i] = field;


heres the full code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <gnls.h>
#include <iostream>
#include <time.h>

#define GHz 0.001

int main(int argc,char *argv []){

  if(argc!=12){
    cout<<"Usage :\n";
    cout<<"mdwdm <Peak_Power> <Pulse_Width> <Chirp> <Innital Freq> <Space> <DeTune> <Filter FileName> <Fgain> <Channels> <# Map>  <QF File Name>\n";
    exit(1);
  }

double peak_power = atof(argv [1]);
  double pulse_width = atof(argv [2]);
  double chirp  = atof(argv [3]);
  //fixed parameters for fibre
  double D=8.0;
  char* filterName=argv[7];
  double S=0.057;
  double loss=0.205;
  double length=50;
  double RD=-16;
  double RS=-0.116;
  double Rloss=0.28;
  double Rlength=25;
  //fixed parameters for signal
  double seperation=25; //for 40Gbit/s
  double num_of_bits=128;
  int field_win=(seperation*num_of_bits)/2;
  double phase=0;
  //Frequency
  double freq=0.0;
  double init_freq=atof(argv [4]);
  double space=atof(argv [5]);
  double f_detune= atof(argv [6]);
  double fgain= atof(argv [8]);
  int channels=atoi(argv [9]);
  int num_map=atoi(argv [10]);
  //Aplifier
  double ampgain=length*loss+Rlength*Rloss;
  double noise=1.5;
  //Qfactor
  ofstream qf_data_stream[(channels)],sample_stream[(channels)],eye_stream[(channels)];
  double cutoff=1000/(seperation*1000);
  int fp=0;
  char num[10];
  char ind[20];
  string qf_file,qf_buff=(argv[11]); //Change
  string eye_file,eye_buff="eye";
  string sample_file,sample_buff="sample";
  //bool minuse_detune=true;
  fgain=0;

//********
  long int seed=0;
  seed=time(0);
  srand48(seed);
//****************

  Loop::break_on_interrupt();
  Fibre::verbosity=true;
  Fibre::unit_system=Fibre::ps_per_nm_per_km;

  Field field((field_win*2),field_win);
  Field *cp_ptr[channels];

  Fibre Teralight(0,D,S,0,1.55,loss,65);
  Fibre RTeralight(0,RD,RS,0,1.55,Rloss,25);
  OutputUnit wdmtera("multiwdm_filt",field);

//*******Opening files for eye diagram and q_factor
    for(fp=0;fp<(channels);fp++){
    //convert int to string and put into  num
    sprintf(num,"%d",fp);
    sprintf(ind, "-%d_%.1f_%.1f",(int)pulse_width,(space*1000),f_detune*1000);
    qf_file=qf_buff+ind+"_C"+num+".dat";
    eye_file=eye_buff+ind+"_C"+num+".dat";
    sample_file=sample_buff+ind+"_C"+num+".dat";

    qf_data_stream[fp].open(qf_file.c_str());
    cout<<"Opened File: "<<qf_file<<"\n";
    qf_file.erase(1);
    eye_file.erase(1);
    sample_file.erase(1);
  }

  //*************GT Gaussian transmitter*****************
  if(channels%2==0)freq=init_freq-(space*0.5+(channels/2-1)*space);
  	else freq=init_freq-(channels-1)/2*space;
  Add G_Pulse;
  for(int i=0;i<channels;i++){
    cout<<"Frequncy channel A: "<<freq<<"\n";
    double posn=-drand48()*num_of_bits*seperation*0.5;
    cout<<"Signal position + "<<-posn<<endl;
    G_Pulse.add_system(
      Gaussian(pulse_width,peak_power,posn,0,0,chirp)
        +GeneratePattern(PRBS(field,7,seperation,0,freq,phase))
	+OutputField(wdmtera)
	+ReadFilter(filterName,(freq-f_detune))
    );

    freq=freq+space;
  }


  //************Transmitter=GT+GF*************************
  System Tx;
  Tx=  G_Pulse +OutputField(wdmtera)
  ;

  //*************TeraLight + RTL Fibre********************

  Add TLFibre;
  TLFibre.add_system(
      FibreSegment(Teralight,length)+
      FibreSegment(RTeralight,Rlength)+
      Amplifier(ampgain,noise,1.55)+
      OutputField(wdmtera)
  );

  Add RTLFibre;
  RTLFibre.add_system(
      FibreSegment(RTeralight,Rlength)+
      FibreSegment(Teralight,length)+
      Amplifier(ampgain,noise,1.55)+
      OutputField(wdmtera)
  );

  //*************System GF+GF+TLfibre*********************
  Tx.propagate(field);
  System mwdmsys;

   for(int k=1;k<=num_map;k++){

	mwdmsys=TLFibre+RTLFibre;
	FixEnergy Att(mwdmsys);
	Att.propagate(field);
  }

  //*************DeMutiplex Field and applie Qfac********

  System C_wdm[(channels)];
  for (int i=0;i<(channels);i++){
  cp_ptr[i] = new Field((field_win*2),field_win);
  *cp_ptr[i] = field;
  }

  //Open Qfactor Files

  if(channels%2==0)freq=init_freq-(space*0.5+(channels/2-1)*space);
  	else freq=init_freq-(channels-1)/2*space;
  fp=0;

  for(fp=0;fp<(channels);fp++){

      C_wdm[fp]=
        ReadFilter(filterName,(freq-f_detune))+
        QFactor(RZ,qf_data_stream[fp],(freq),10,cutoff*1.0,seperation,64)
        +OutputField(wdmtera)
	;

      freq=freq+space;

      C_wdm[fp].propagate(*cp_ptr[fp]);
      }

  //*************Closing all QFac Files*******************
  //Close all QFACTOR files and cleanup
  cout<<"Closing all Qfactor files: \n";
  for(fp=0;fp<(channels);fp++){
    qf_data_stream[fp].close();
    cout<<"Closing File Number: "<<fp<<"\n";
  }

  for (int i=0;i<(channels);i++){
  delete cp_ptr[i];
  }

  return 0;
}

Last edited on
Undefined reference error means that the compiler knows about some function, but can't find what it is. I can't say why it would only complain about =, but not about constructor or etc. I can only suggest to check your linker options, look at the relevant header and, maybe, if you have the sources, at the library code.
Last edited on

so its an undefined reference linker error....do you have any suggestions what to look for specifically?
Topic archived. No new replies allowed.