Click to See Complete Forum and Search --> : C++ linker errors
His Eaziness
11-11-2003, 08:40 PM
using MS visual C++ 6.0
on XP Pro
Dell p4 2.4, 512 mb rdram, etc.
i'm writing a driver for my BigUn class (Big Unsigned) which essentially implements the unsigned datatype with a linked list allowing for virtually infinitely big unsigned numbers. the BigUn class uses a SlistT<unsigned> object (Singly linked list templated to unsigned) to hold the number. all of my files compile, and i have all the *.cpp files added to the project and all of the *.h files are included properly. the problem i'm running into is that the linker still gives me LNK2001 errors(usually means *.cpp isnt included or doesnt exist or function implementation cant be found).
i'd attach the files, but the forum doent provide for it.
thx
His Eaziness
fishybawb
11-12-2003, 08:45 AM
Is there any way you could upload the files to some webspace? We really need to see the code to know what's going on, and I suspect it's a bit long to just "cut and paste" :t
His Eaziness
11-14-2003, 11:15 AM
is there a way to post the souce files on a geocities site? i tried to upload them with the filemanager and it said they were invalid file types.
His Eaziness
fishybawb
11-14-2003, 02:27 PM
Attach them to an email and send them to me - I'll post them up somewhere and then provide a link for anyone else who wants to help.
fishybawb@yahoo.com
:t
His Eaziness
11-14-2003, 02:52 PM
thx fishybawb
His Eaziness
fishybawb
11-14-2003, 03:09 PM
Click here for Eaziness's source files (http://www.btinternet.com/~hull.family/SysOpt/code.htm)
I'll have a look in a bit :)
neverwhere
11-14-2003, 03:28 PM
Ok, here is my first thing (Prog9.cpp)
cin >> temp1;
first = temp1;Why not just cin >> first; ?
SlistT.cpp
#include <iostream>Dont you need a .h in there? Every time I've included with the <> its always had a .h in it. Maybe it doesnt matter, but its just what Ive had to use.
Oh, and I cant get to SlistT.h file fishy :D
fishybawb
11-14-2003, 03:32 PM
OK, I see what you've done. The problem is that the template doesn't get instantiated because the information (declaration and implementation) are in seperate files (and compiled seperately), causing the linker to get confused by the lack of template definition for SlistT<unsigned>. Anyway, the solution is to cut out all the code out from SlistT.cpp and add it to SlistT.h, then it compiles.
:t
His Eaziness
11-14-2003, 03:34 PM
i didnt set up and overloaded cin operator when i wrote the BigUn class last year, and i figured out of laziness i would stick with setting a BigUn var equal to a string of ints via my overloaded assignment operator.
the .h after iostream doesnt matter in most cases
His Eaziness
fishybawb
11-14-2003, 03:34 PM
Dont you need a .h in there? Every time I've included with the <> its always had a .h in it. Maybe it doesnt matter, but its just what Ive had to use.
No, because the std namespace is being used.
Oh, and I cant get to SlistT.h file fishy :D
Doesn't matter now :p :D
neverwhere
11-14-2003, 03:41 PM
Whee, I actually learned something today. :D
**** you and your speed!
fishybawb
11-14-2003, 03:48 PM
Originally posted by fishybawb
OK, I see what you've done. The problem is that the template doesn't get instantiated because the information (declaration and implementation) are in seperate files (and compiled seperately), causing the linker to get confused by the lack of template definition for SlistT<unsigned>. Anyway, the solution is to cut out all the code out from SlistT.cpp and add it to SlistT.h, then it compiles.
Oh yeah, and don't forget to delete the SlistT.cpp file from the project once you've done that ;)
His Eaziness
11-14-2003, 03:49 PM
that works to get the file linked...but shouldnt the #include "SlistT.h" at the begining of SlistT.cpp make the compiler add the SlistT.h code at the top of the SlistT.cpp code-essentially doing the same thing.
neverwhere
11-14-2003, 03:53 PM
it should
His Eaziness
11-14-2003, 03:54 PM
PS. for those of you trying to run the proggy and thinking man...what a dumbass all it does is append the second # to the first #...you're right i screwed up...going back to the non overloaded cin operator i initially tried it then realized that i didnt have one and never changed the var names on the addition line.
sum = temp1 + temp2;
should read
sum = first + second;
His Eaziness
fishybawb
11-14-2003, 03:58 PM
Yeah, you would think so wouldn't you? It's just one of the peculiarities of the linker when you're using templates. The definition of the SlistT template doesn't get instantiated, hence the linker errors. In order for it to be instantiated, the compiler needs the definition and for what arguments it should be instantiated. Since the definition and the implementation are compiled seperately, when the compiler finds a reference to SlistT<unsigned> but can't find the definition for it (it's in the other file - as yet uncompiled), it leaves it up to the linker to resolve, which it can't as it doesn't know for what arguments the template should be instantiated. I have a feeling I've explained that pretty badly, but just accept it ;)
neverwhere
11-14-2003, 04:19 PM
good explanation
SysOpt.com
Copyright Internet.com Inc. All Rights Reserved.