Linker Error for static template, undefined reference. Help.

Iain Walsh walshi3@cs.man.ac.uk
Mon Nov 21 12:41:00 GMT 2005


#include <QVector>

#include "TreeNode.cpp"
#include "File.h"
class FileSet
{

public:
static QVector<File> * allFiles;
QVector<File> *files;
TreeNode * rootNode;
static void setAllFiles(QVector<File> *files)
{
allFiles=files;
}

FileSet(FileProperty property)
{
rootNode=new TreeNode(property);
files=new QVector<File>(1);
for(int i=0;i<allFiles->size();i++)
{
if(allFiles->value(i).Search(property))
{
files->append(allFiles->value(i));
}
}
}
//void rebuild();
//static void addNewFile(File newfile);
//static void deleteFile(File oldFile);
//static FileSet unionOfSets(FileSet a, FileSet b);

//static FileSet conjunctionOfSets(FileSet a, FileSet b);

//static FileSet negationOfSets(FileSet a, FileSet b);
};

compiling this I get

g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_CORE_LIB -DQT_GUI_LIB 
-DQT_XML_LIB -DQT_SHARED 
-I/usr/local/Trolltech/Qt-4.0.1/mkspecs/linux-g++ -I. 
-I/usr/local/Trolltech/Qt-4.0.1/include/QtXml 
-I/usr/local/Trolltech/Qt-4.0.1/include/QtGui 
-I/usr/local/Trolltech/Qt-4.0.1/include/QtCore 
-I/usr/local/Trolltech/Qt-4.0.1/include -I. -I. -I. -o main.o main.cpp
main.cpp:7: warning: unused parameter ‘argc’
g++ -Wl,-rpath,/usr/local/Trolltech/Qt-4.0.1/lib -o FileSetBuilding 
File.o main.o XmlFileHandler.o -L/usr/local/Trolltech/Qt-4.0.1/lib 
-L/home/walshi3/QTDownload/qt-x11-opensource-src-4.0.1/lib -lQtGui_debug 
-L/usr/X11R6/lib -lpng -lSM -lICE -lXi -lXrender -lXrandr -lXcursor 
-lXinerama -lfreetype -lfontconfig -lXext -lX11 -lm -lQtXml_debug 
-lQtCore_debug -lz -ldl -lpthread
main.o(.gnu.linkonce.t._ZN7FileSet11setAllFilesEP7QVectorI4FileE[FileSet::setAllFiles(QVector<File>*)]+0x7): 
In function `FileSet::setAllFiles(QVector<File>*)':
/OSSwap/Iain/My Documents/Third Year 
Project/FileMockUpClasses/Building/FileSetBuilding/FileSet.cpp:14: 
undefined reference to `FileSet::allFiles'
main.o(.gnu.linkonce.t._ZN7FileSetC1E12FileProperty[FileSet::FileSet(FileProperty)]+0x101): 
In function `FileSet::FileSet(FileProperty)':
/OSSwap/Iain/My Documents/Third Year 
Project/FileMockUpClasses/Building/FileSetBuilding/FileSet.cpp:23: 
undefined reference to `FileSet::allFiles'
main.o(.gnu.linkonce.t._ZN7FileSetC1E12FileProperty[FileSet::FileSet(FileProperty)]+0x192):/OSSwap/Iain/My 
Documents/Third Year 
Project/FileMockUpClasses/Building/FileSetBuilding/FileSet.cpp:25: 
undefined reference to `FileSet::allFiles'
main.o(.gnu.linkonce.t._ZN7FileSetC1E12FileProperty[FileSet::FileSet(FileProperty)]+0x1f8):/OSSwap/Iain/My 
Documents/Third Year 
Project/FileMockUpClasses/Building/FileSetBuilding/FileSet.cpp:21: 
undefined reference to `FileSet::allFiles'
collect2: ld returned 1 exit status
make: *** [FileSetBuilding] Error 1

I don't get why the linker is giving me problems when it just needs a 
member of itself.



More information about the Gcc-help mailing list