From: Robert M D. <bob...@us...> - 2003-01-15 15:14:25
|
I'd like to keep template declarations and template definitions in separate files; however, I encounter the following error when trying to compile and link a simple example (taken from p. 351, Stroustrup 2000 The C++ Programming Language). C:\MyC++SourceCode\Templates>mingw32-make g++.exe -c driver.cc -o driver.o -Ic:/MinGW/include -Ic:/MingGW/include/c++/3.2 -ftemplate-depth-30 -Wno-deprecated -s -ansi g++.exe -c Out.cc -o Out.o -Ic:/MinGW/include -Ic:/MingGW/include/c++/3.2 -fte mplate-depth-30 -Wno-deprecated -s -ansi g++.exe driver.o Out.o -o pgm.exe -Lc:/MinGW/lib -Ic:/MinGW/include -Ic:/MingGW /include/c++/3.2 -ftemplate-depth-30 -Wno-deprecated -s -ansi driver.o(.text+0x34):driver.cc: undefined reference to `void out<double>(double const&)' mingw32-make: *** [pgm.exe] Error 1 Perhaps I'm missing some compiler flags? I'm sure the error is probably embarassingly simple, but any help is greatly appreciated. I'm using MinGW 2.0.0-3. The following list includes the makefile and source code: makefile ************************************************************************** CC = g++.exe LIBS = -Lc:/MinGW/lib INCS = -Ic:/MinGW/include -Ic:/MingGW/include/c++/3.2 # Flags for normal development CXXFLAGS = -ftemplate-depth-30 -Wno-deprecated CFLAGS = $(INCS) $(CXXFLAGS) -s -ansi OBJ = driver.o Out.o TARGET = pgm.exe .PHONY: all all-before all-after clean clean-custom all: all-before $(TARGET) all-after clean: clean-custom rm -f $(OBJ) $(TARGET) $(TARGET): $(OBJ) $(CC) $(OBJ) -o $(TARGET) $(LIBS) $(CFLAGS) driver.o: driver.cc $(CC) -c driver.cc -o driver.o $(CFLAGS) Out.o: Out.cc $(CC) -c Out.cc -o Out.o $(CFLAGS) driver.cc ************************************************************************** #include "Out.h" int main() { double x = 55.; out(x); return 0; } out.h ************************************************************************** template<class T_numtype> void out(const T_numtype& t); out.cc ************************************************************************** #include "out.h" #include <iostream> export template<class T_numtype> void out(const T_numtype& t) { std::cout << t; } ****************************************************************************** Bob Dorazio United States Geological Survey 7920 NW 71 Street Gainesville, Florida 32653 Phone: (352) 378-8181 x373 Fax: (352) 378-4956 Email: bdo...@us... Internet: www.fcsc.usgs.gov |