Skip to main content
GameDev.net gamedev.net
🔒 Locked

Major Linking Problem

Started by Cornflake420 Aug 1, 2005 at 6:09 PM 12 replies 1.3k views
Original Post
Cornflake420
Cornflake420
When I try building my project, I get a very large list of problems. I would list them, but there are literally over 500 errors. My project compiles perfectly fine, but linking it recently started giving me errors like

In function `vector<View, allocator<View> >::begin(void) const':
multiple definition of `__copy_backward_dispatch<Node **, Node **, __true_type>::copy(Node *const *, Node *const *, Node **)'
These aren't functions I wrote myself, but functions that belong to the STL. All of the errors pertain to functions in the STL, which I need in all of my source code files. I can't remove the
#include <stl.h>
lines because that causes the program to fail to compile. If anyone could help me, please respond.
Xai
Xai
what the hell is #include ????

the C++ way is stuff like:

#include
#include
#include

etc ...

show us like the top 15 lines of 2 of your files ... and maybe the top 20 lines of that stl.h file ...
Cornflake420
Cornflake420
Inside "stl.h"
#include <algorithm>#include <deque>#include <functional>#include <iterator>#include <list>#include <map>#include <memory>#include <numeric>#include <set>#include <stack>#include <utility>#include <vector>


Since I only use vectors, I tried replacing "stl.h" with , but I am still getting the same huge list of problems.

At the top of all of my files, there is a line that includes this:
#ifndef __STDINCS_H__#define __STDINCS_H__typedef unsigned char uchar;typedef unsigned short ushort;typedef unsigned int uint;typedef unsigned long ulong;typedef unsigned char byte;#include <windows.h>#include <gl/gl.h>#include <gl/glu.h>#include <vector>#define _DEBUG#include "debug.h"#include "globals.h"#include "log.h"#include "render.h"#include "scene.h"#include "vector2.h"#include "vector3.h"#include "vector4.h"#include "vertex.h"#include "world.h"#endif // __STDINCS_H__


I have already tried removing the STL inclusion from this file and putting it in only the files that need it, but I am continuing to get the errors.
garyfletcher
garyfletcher
Do you know where in your code the linker is hiting the problem? Can you show that bit(s) of code?
Gary.Goodbye, and thanks for all the fish.
Cornflake420
Cornflake420
The linker is giving errors for every object being linked to the executable. It doesn't report line numbers for object files.
ZQJ
ZQJ
What compiler and C++ library are you using?

Edit: along the lines of that thought I'm going to guess you're using Visual C++ and SGI or GNU STL headers. Anyway even if I'm wrong about that my best guess would be the compiler doesn't support template specialisations (or whatever it's called), although I'd expect this to show up in the compiler not the linker not I might be very wide of the mark. The reason I mention it is that VC++6 doesn't have full template support.
Cornflake420
Cornflake420
I am using GCC. It supports templates perfectly fine; the problem is that it gives a huge list of "multiple definition" errors. I know what the problem is, but I don't know how to fix it. Every source file needs STL, so every object file has the functions for the STL compiled in it. Then, when the linker combines the object files into an executable, it finds the same functions in all of the files and gives an error. Five-hundred one errors, actually.

I need a suggestion on how to use the STL in all source files without this problem.
Abbacabba
Abbacabba
Steps I would take:

Clean your build. Most IDE's have a simple option to clean all old files from previous builds. Use that if you have it... else just go delete all the files in your build directory(assumes your build and source are not in the same directory).




Create a new blank project.
Include your stl.h and just do an empty main().. see if that links.
If it does, do some basic stuff with vector and try again.
This could help identify exactally where the break down occurs.


Cornflake420
Cornflake420
I already tried a clean rebuild.

In a simple project, the STL compiles and links without a problem. In my real project, every object file has tons of errors saying that each STL function has already been defined. I need to know some possible causes of the problem.
Mantear
Mantear
It sounds like multiple files are trying to include your stl.h file. Try to put header guards in your stl.h file and see if that fixes it.
Cornflake420
Cornflake420
No, the header files all have inclusion guards. Besides, that would cause a compiling error, not a linking error.
Cornflake420
Cornflake420
I just fixed the problem, however, I don't know how. I restored an older backup copy of my project and recompiled it. It worked, so I added my newer code back into it and the errors are gone. Because I still don't know why the problem started in the first place, I am still open to suggestions on why the problems occured, but this isn't a big deal anymore.
pinacolada
pinacolada
*shrug* Sometimes the compiler gets confused and spits out bad object files, and the fix is as simple as doing a clean and "rebuild all".
Xai
Xai
did you perhaps change any compiler / linker options ... between the original project and the other day ... perhaps accidentally?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.