what to do when missing files from library


When i try to compile my Main.cc file with my Makefile, I get a compilation error.

Im getting undefined references to an element called ReadFilter. Ive tried going into the library and adding the missing ReadFilter.cc ReadFilter.o and ReadFilter.h files but i still get the same message.

This is what im seeing:

frenchcr@n516-5:~/src/mdwdm
$ make
c++ -g -O3 -Wall -Wstrict-prototypes -Wno-deprecated -fno-exceptions
-I/home/frenchcr/src/fss0/src
-L/home/frenchcr/src/fss0/src
-L/apps/gcc64/fftw2/lib
-I/apps/gcc64/fftw2/include
-I/apps/gnu64/gsl-1.8/include
-L/apps/gnu64/gsl-1.8/lib
-I/home/frenchcr/src/FEC/src
-L/home/frenchcr/src/FEC/src Main.o  -o Main  -lfec -lgnls -lfftw -lgsl -lgslcblas -lm

Main.o(.text+0x8b3): In function `main':
/usr/include/g++/x86_64-suse-linux/bits/gthr-default.h:512: undefined reference to `ReadFilter::~ReadFilter [in-charge]()'
Main.o(.text+0x9a2): In function `main':
/home/frenchcr/src/mdwdm/Main.cc:109: undefined reference to `ReadFilter::ReadFilter[in-charge](char*, double)'
Main.o(.text+0x10d9):/home/frenchcr/src/mdwdm/Main.cc:204: undefined reference to `Field::operator=(Field const&)'
Main.o(.text+0x132d):/home/frenchcr/src/mdwdm/Main.cc:231: undefined reference to `ReadFilter::ReadFilter[in-charge](char*, double)'
Main.o(.text+0x1397):/home/frenchcr/src/mdwdm/Main.cc:231: undefined reference to `ReadFilter::~ReadFilter [in-charge]()'
collect2: ld returned 1 exit status
make: *** [Main] Error 1

Last edited on
Did you write that library yourself? if yes, make sure it doesn't use templates, and if it does, make sure that the implementations of your functions are in the header file with the definitions.

If it's not your library, keep in mind that it's recommended always to have the same compiler compile the library and your program. If you can recompile that library and retry, then do it.

Undefined reference means simply that a definition of the file can be found but its implementation isn't available.
Last edited on

I didnt write the library, i just have a copy of it. I dont know enough to know if it uses templates. im quite new.

How do i recompile it?
How do i make the implementation available?
Last edited on
OK, let's forget about recompiling.

You have to include the cpp/o files in your compilation process. Usually it goes like that:

c++ -g Main.o ReadFilter.o ...

Are you using an IDE? if yes, you have to add this file to your IDE files list.
Im using a Makefile, this is it:

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
CXX=c++

LOCALFLAGS = -I/home/frenchcr/src/fss0/src 			 \
	     -L/home/frenchcr/src/fss0/src     			 \
	     -L/apps/gcc64/fftw2/lib -I/apps/gcc64/fftw2/include \
	     -I/apps/gnu64/gsl-1.8/include -L/apps/gnu64/gsl-1.8/lib     \
	     -I/home/frenchcr/src/FEC/src		 \
	     -L/home/frenchcr/src/FEC/src


CXXFLAGS= -g -O3 -Wall -Wstrict-prototypes -Wno-deprecated \
          -fno-exceptions  $(LOCALFLAGS)

progsrc = Main.cc

progobj = $(progsrc:.cc=.o) 

prog = Main 

all : Main 

default: Main

$(prog): $(progobj)
	$(CXX) $(CXXFLAGS) $(progobj) -o $(prog) -lfec -lgnls -lfftw -lgsl -lgslcblas -lm

%.o: %.cc %.h
	$(CXX) $(CXXFLAGS)  -c $<

#Main: ReadFilter.o

clean:
	-rm *.o Main Main.job




As you can see i added this: Main: ReadFilter.o ...then commented it out as it said it had no rule for this.
Last edited on
Change this line

progsrc = Main.cc

to

progsrc = Main.cc ReadFilter.cc

..added it to the makefile...

..it seemed to get on a bit more, then it threw out lots of these (too many to list all) compile error messages:

ReadFilter.o(.ComplexFilter::gnu.linkonce.t.(ComplexFilter const &)+0x77): In function `ComplexFilter::ComplexFilter(ComplexFilter const &)':
: undefined reference to `SystemElement::~SystemElement(void)'
ReadFilter.o(.ComplexFilter::gnu.linkonce.t.(ComplexFilter const &)+0x83): In function `ComplexFilter::ComplexFilter(ComplexFilter const &)':
: undefined reference to `__throw'
ReadFilter.o(.ComplexFilter::gnu.linkonce.t.(ComplexFilter const &)+0x91): In function `ComplexFilter::ComplexFilter(ComplexFilter const &)':
: undefined reference to `terminate(void)'
ReadFilter.o(.gnu.linkonce.t._._Q2t24__default_alloc_template2b1i0_5_Lock+0x2c): In function `__default_alloc_template<true, 0>::_Lock::~_Lock(void)                                                                                         ':
: undefined reference to `__builtin_delete'
ReadFilter.o(.gnu.linkonce.t._._t12_Vector_base2Zt7complex1ZdZt9allocator1Zt7complex1Zd+0x3a): In function `_Vector_base<complex<double>, allocator<                                                                                         complex<double> > >::~_Vector_base(void)':
: undefined reference to `__builtin_delete'
ReadFilter.o(.gnu.linkonce.t._._t12_Vector_base2ZdZt9allocator1Zd+0x3a): In function `_Vector_base<double, allocator<double> >::~_Vector_base(void)'                                                                                         :
: undefined reference to `__builtin_delete'
ReadFilter.o(.vector<complex<double>, allocator<complex<double> > >::gnu.linkonce.t.(vector<complex<double>, allocator<complex<double> > > const &)+                                                                                         0x41): In function `vector<complex<double>, allocator<complex<double> > >::vector(vector<complex<double>, allocator<complex<double> > > const &)':
: undefined reference to `__throw'
ReadFilter.o(.vector<complex<double>, allocator<complex<double> > >::gnu.linkonce.t.(vector<complex<double>, allocator<complex<double> > > const &)+                                                                                         0x91): In function `vector<complex<double>, allocator<complex<double> > >::vector(vector<complex<double>, allocator<complex<double> > > const &)':
: undefined reference to `__throw'
ReadFilter.o(.vector<complex<double>, allocator<complex<double> > >::gnu.linkonce.t.(vector<complex<double>, allocator<complex<double> > > const &)+                                                                                         0xc8): In function `vector<complex<double>, allocator<complex<double> > >::vector(vector<complex<double>, allocator<complex<double> > > const &)':
: undefined reference to `__throw'
ReadFilter.o(.vector<complex<double>, allocator<complex<double> > >::gnu.linkonce.t.(vector<complex<double>, allocator<complex<double> > > const &)+                                                                                         0xd3): In function `vector<complex<double>, allocator<complex<double> > >::vector(vector<complex<double>, allocator<complex<double> > > const &)':
: undefined reference to `terminate(void)'
ReadFilter.o(.vector<double, allocator<double> >::gnu.linkonce.t.(vector<double, allocator<double> > const &)+0x41): In function `vector<double, all                                                                                         ocator<double> >::vector(vector<double, allocator<double> > const &)':
: undefined reference to `__throw'
ReadFilter.o(.vector<double, allocator<double> >::gnu.linkonce.t.(vector<double, allocator<double> > const &)+0x91): In function `vector<double, all                                                                                         ocator<double> >::vector(vector<double, allocator<double> > const &)':
: undefined reference to `__throw'
ReadFilter.o(.vector<double, allocator<double> >::gnu.linkonce.t.(vector<double, allocator<double> > const &)+0xc8): In function `vector<double, all                                                                                         ocator<double> >::vector(vector<double, allocator<double> > const &)':
: undefined reference to `__throw'
ReadFilter.o(.vector<double, allocator<double> >::gnu.linkonce.t.(vector<double, allocator<double> > const &)+0xd3): In function `vector<double, all                                                                                         ocator<double> >::vector(vector<double, allocator<double> > const &)':
: undefined reference to `terminate(void)'
ReadFilter.o(.complex<double> gnu.linkonce.t.__mi<double>(complex<double> const &, complex<double> const &)+0x63): In function `complex<double> oper                                                                                         ator-<double>(complex<double> const &, complex<double> const &)':
: undefined reference to `complex<double>::complex(double, double)'
ReadFilter.o(.complex<double> gnu.linkonce.t.__pl<double>(complex<double> const &, complex<double> const &)+0x63): In function `complex<double> oper                                                                                         ator+<double>(complex<double> const &, complex<double> const &)':
: undefined reference to `complex<double>::complex(double, double)'
ReadFilter.o(.basic_string<char, string_char_traits<char>, __default_alloc_template<true, 0> >::gnu.linkonce.t.assign(char const *)+0x16): In functi                                                                                         on `basic_string<char, string_char_traits<char>, __default_alloc_template<true, 0> >::assign(char const *)':
: undefined reference to `string_char_traits<char>::length(char const *)'
ReadFilter.o(.gnu.linkonce.t.__tf13SystemElement+0x1d): In function `SystemElement type_info function':
: undefined reference to `__rtti_user'
ReadFilter.o(.gnu.linkonce.d.__vt_10ReadFilter+0x8): undefined reference to `ComplexFilter::propagate(Field &)'
ReadFilter.o(.gnu.linkonce.d.__vt_10ReadFilter+0xc): undefined reference to `ComplexFilter::propagate(VectorField &)'
ReadFilter.o(.gnu.linkonce.d.__vt_10ReadFilter+0x10): undefined reference to `ComplexFilter::propagate(VariationalField &)'
ReadFilter.o(.gnu.linkonce.d.__vt_13SystemElement+0x8): undefined reference to `__pure_virtual'
ReadFilter.o(.gnu.linkonce.d.__vt_13SystemElement+0xc): undefined reference to `__pure_virtual'
ReadFilter.o(.gnu.linkonce.d.__vt_13SystemElement+0x10): undefined reference to `__pure_virtual'
ReadFilter.o(.gnu.linkonce.d.__vt_13SystemElement+0x14): undefined reference to `__pure_virtual'
ReadFilter.o(.gnu.linkonce.d.__vt_13SystemElement+0x18): undefined reference to `__pure_virtual'
collect2: ld returned 1 exit status
make: *** [Main] Error 1


Last edited on
Do the same, add ComplexFilter.cc to the files list. Keep adding all the files that are claimed with no reference.
That cant be right. Ive already got a header .h file that shows main where they are.
The header contains declerations, not implementations. That's why you're getting that error. All cc or cpp files have to be passed to the compiler manually. It's the way stuff are done in C++.

That's why it's more practical if you'd use an IDE and have them all included automatically to your project, which generates the makefile for your automatically.
Thanks TheDestroyer, I had to recompile the library to include the missing file. The makefile that i used to compile the library is different from this makefile. The makefile i needed to ammend sat in beside the .cc .o and header folder. I dont use an IDE as i work in Linux only.
Last edited on
Topic archived. No new replies allowed.