Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't link program where my own templates are used

Status
Not open for further replies.

alebu

Programmer
Sep 7, 2002
46
Hi!
I am using borland c++ compiler 5.5 ( free ).
The sructure of program is very simple: Program.cpp, containing main() function, Array.cpp and Indexed.cpp with my templates.
Those 3 files was succesfully compiled( got Program.obj, Array.obj, Indexed.obj ), but when I trying to link em, I got 'Unresolved external...'. It seems that linker doesn't see classes generated by templates.
Make file is:
-----
CXX = blablabla\bcc32.exe
CXXFLAGS = -5 -O2 -w-par -w-csu -w-aus
DEFINES = -DNDEBUG -DWIN32 -D_WINDOWS
LD = blablabla\bcc32.exe
LDFLAGS = -lap

Program.exe: Program.obj Array.obj Indexed.obj
$(LD) $(LDFLAGS) Program.obj Array.obj Indexed.obj

Program.obj:
$(CXX) -c $(CXXFLAGS) $(DEFINES) Program.cpp

Indexed.obj:
$(CXX) -c $(CXXFLAGS) $(DEFINES) Indexed.cpp

Array.obj:
$(CXX) -c $(CXXFLAGS) $(DEFINES) Array.cpp
-----
But results are:
-----
Error: Unresolved external 'Array<int>::~Array<int>()' referenced from D:\LAB\CP
P\DATALIB\PROGRAM.OBJ
Error: Unresolved external 'Array<int>::Array<int>(int)' referenced from D:\LABCPP\DATALIB\PROGRAM.OBJ
Error: Unresolved external 'Indexed<int>::get_min_index() const' referenced from
D:\LAB\CPP\DATALIB\PROGRAM.OBJ
Error: Unresolved external 'Array<int>::set_at(int, int)' referenced from D:\LAB
\CPP\DATALIB\PROGRAM.OBJ
Error: Unresolved external 'Array<int>::get_at(int) const' referenced from D:\LA
B\CPP\DATALIB\PROGRAM.OBJ
Error: Unresolved external 'Indexed<int>::get_max_index() const' referenced from
D:\LAB\CPP\DATALIB\PROGRAM.OBJ
-----
Should I add some options to linker or change something in my sources?
 
Try to do this : if all of the code for template classes is not already in the class itself, instead of writing template code in .cpp file, put it in e.g. &quot;.inl&quot; file (inline). Then at the end of your template-header file put #inlude &quot;Array.inl&quot;. Do it for every header file with templateized class and it should link.
But, first be absolutely sure that you don't have any syntax-errors in .cpp files!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top