Mac Zerolink problems

mmmdreg

macrumors 65816
Original poster
Apr 14, 2002
1,393
0
Sydney, Australia
A program I'm writing compiles fine at this stage, yet when running, I get this error:
ZeroLink: unknown symbol '__ZN14linkedListTypeIiEC1Ev'

To show where the error occurs, from the following code, "debug1" is printed, but it never reaches "debug2":
Code:
int main()
{
	int theInput = 0;
	cout << "debug1" << endl;
	linkedListType<int> myList;
	cout << "debug2" << endl;
 

mmmdreg

macrumors 65816
Original poster
Apr 14, 2002
1,393
0
Sydney, Australia
I turned zerolink off and now it won't compile, giving me "undefined symbols" for various member functions of my template class. Does turning off zerolink screw things up with template classes?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
24,596
60
Harrogate
I'm not using XCode for C++ but if you turn of zerolink you will need to do a clean build to get it to work as some of your files will have been compiled with zerolink and some other won't!
 

mmmdreg

macrumors 65816
Original poster
Apr 14, 2002
1,393
0
Sydney, Australia
I found some help. This site shows pretty much the problems with using template classes. To get around it, I included the classImplementation.cpp file at the bottom of the header file, and removed the inclusion of the header in the class implentation file. Then I had the class header file included in the main .cpp file.

This is when i found a possible xcode bug. There are three files. the class header, the class cpp, and the main cpp. Xcode tries to compile the class cpp which doesn't include the header file so it has many errors. Meanwhile, doing:
"g++ -o theApp theMainFile.cpp"
yields no errors and a perfect executable. Is this a bug or just some thing I overlooked?
 
mmmdreg said:
I found some help. This site shows pretty much the problems with using template classes. To get around it, I included the classImplementation.cpp file at the bottom of the header file, and removed the inclusion of the header in the class implentation file. Then I had the class header file included in the main .cpp file.

This is when i found a possible xcode bug. There are three files. the class header, the class cpp, and the main cpp. Xcode tries to compile the class cpp which doesn't include the header file so it has many errors. Meanwhile, doing:
"g++ -o theApp theMainFile.cpp"
yields no errors and a perfect executable. Is this a bug or just some thing I overlooked?
Xcode (and just about every IDE) will infer some sort of meaning from the extension you give your files. In the case of cpp, you are telling Xcode that you want to compile this file. Using cpp for a template implementation is only going to be acceptable if you can control which files are passed to the compiler, as you do with the command line compile ... using an IDE is one way of saying that you don't want to be bothered with this level of detail!

Either use a different extension (er, maybe tpp or txx - you can tell Xcode that these types contain c++ code to get your syntax highlighting) or stick the whole implementation in the header file.