Archived

This topic is now archived and is closed to further replies.

HELP! Is this a VS6.0 Bug?

This topic is 5115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

O.k, so I have a rather hefty class, and I decided to break up the implementation into several files. I have about 3 different files. Organized as myClass.cpp myClassUtilities.cpp myClassTexturing.cpp (They all only deal with one class) I added another class function into the utilities file. And properly defined it in myClass.h I get a "error LNK2001: unresolved external symbol" error for this new function. They are all filled with implementations of class functions, so I can rule out a linker problem. O.k, I think, must be some sort of syntax error. So I copied and pasted the function declaration in the .h file into the cpp files. No change. So I made yet another function, called it tst(), same error. There are lots of other implementations of class functions in this file, so it can't be a linker thing. O.k, so I thought I would cut the implementation from myUtilities and paste it into mtClass. Woah, everything compiles. Then to be silly, I pasted the implementation into myUtilities and kept in myClass. Even though many many functions in myClass call functions defined in myUtilities the compiler compiled code with two identical function definitions. Just for fun, I cut and pasted it into the myTexturing file. Same linker problems. Now the only thing in these files are implementation of 1 class, it's all worked for weeks, and suddenly I can only put implementations into one file. Is there some sort of limit as to how many definitions can exist in multiple files? Is this some sort of documented bug in VS that I don't know about? I'm loosing my sanity here. [edited by - ataru on December 15, 2003 6:40:10 PM]

Share this post


Link to post
Share on other sites
The definitions you had in your CPP file were probably inlined or templated. When you are using inlined functions or templating (without export) you must include the definitions inside a header file (or some other file in some way included by the other modules). This is not a flaw of Visual C++ 6.0, but rather, it''s how the language works.

Share this post


Link to post
Share on other sites
There are some MSVC6 problems, at least according to this, and I''ve heard it doesn''t full support templates. I just ran into the problem with it not allowing forward declarations of templates this weekend.

It''s hard to tell what your problem was without some code.

Tadd
- WarbleWare

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Something smells wrong here - as this should work just fine. I have probably 35 projects, written with VC6 SP5 that are structured the same way. A few things to consider, but these are all gueses unless you post some code examples:

Poly-OOP is correct, inlines and templates can be a bit of a hassle and a C++ issue. I personally place all inlines for a class in their own file (.inl) and include that at the botton of the class declaration for its appropriate header file.

Always use inclusion guards. Usually doesn''t result in a linker error but it can if you have multiple globals being defined where you should only have one. Personally I never define globals in a header - declare in header define in code, but that''s up to you.

Perform a complete clean and rebuild when you do a restructure like this. Often you will have .obj files lying around that are depreciated and when you try to link with them - voila, linker error (the benefits and hassles of an incremental build). Force a clean compile to eliminate this.

Ensure you have patched VC6 with the latest Service Pack (5 I think). While you are at it, install the processor pack (allows you to compile 16bit alined data and make better use of SSE2 - the DX utility stuff, IE vectors and math, will love you here but you have to cheat to get it to work - just declare that you are using a later compiler version.. ONLY IF YOU INSTALL THE PROCESSOR PACK THOUGH!).

If you really want to be smooth, and I know you do, order the DDK from Microsoft, its about $10 which covers media and postage. It includes the latest compiler - you will have to manually copy it into a directory and get your IDE to work with it but it''s a free (almost) compiler upgrade. The newer compiler is MUCH more compliant with STL and produces better optimized code.


Most of these suggestions are not necessary to fix your problem, the first couple of steps will probably take care of it. However VC6 is sort of old (I like it though - .net 2003, while nice is a beast), but if you take these steps it should "upgrade you" and avoid a lot of the problems that reana1 mentioned.


l8r -

Share this post


Link to post
Share on other sites
quote:
Original post by Ataru


I get a "error LNK2001: unresolved external symbol" error


[edited by - ataru on December 15, 2003 6:40:10 PM]



All that means is you declared a function somewhere in your header files, but no function body can be found. Make sure all the functions in your headers have some sort of body, and make sure all .cpp files are part of the project, or that you made the lib including all the cpp files.

Share this post


Link to post
Share on other sites
Thanks guys.

I''m not using any templates in this class, and it is not a template itself.

RhoneRanger, I did give a function body, that''s why I posted here.

Unless I was just tired I had not inlined the deffinition in the header.

it was really simple, like:

in the header''s class def I had

void tst();

and then in one of the .cpp files I had something like


void myClass::old()
{
}

void myClass::tst()
{
}

and then when I use old everything compiles, when I ust tst() it does not. So it''s not got anything to do with inlining.

I did re-build, but I did not try to remove all .obj files. That is something to try. Also, I doubt I have had any service packs installed, all that is handled by our admin, so I doubt he did that.

I''ll try updating and re-building. I hope this fixes things as it''s a huge class, and the thought of having to have it all in one file now scares me.

Share this post


Link to post
Share on other sites
Nope.

Updated to SP5, deleted all the intermediate files. Same thing. This has got to be a rare un-documented VS6 bug, no other way I can explain it.

Share this post


Link to post
Share on other sites