Major Linking Problem

Started by
12 comments, last by Xai 18 years, 8 months ago
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.
Advertisement
what the hell is #include <stl.h>????

the C++ way is stuff like:

#include <vector>
#include <algorithm>
#include <cctype>

etc ...

show us like the top 15 lines of 2 of your files ... and maybe the top 20 lines of that stl.h file ...
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 <vector>, 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.
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.
The linker is giving errors for every object being linked to the executable. It doesn't report line numbers for object files.
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.
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.
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.


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.
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.

This topic is closed to new replies.

Advertisement