I've been having a problem with the program I'm trying to code in Dev C++
4.9.9.2. I have main.cpp and main.h as the, well, main meat of the program,
with two classes (a data type and a keyed linked-list) each declared in their
own .h file and defined in their own .cpp file. Everything compiles to object
code quite nicely, but when I put references in main.cpp to functions defined
in one of the other .cpp files, it gives me a linker error saying that the
function was not defined.
I tried adding the object code to the project (under Project > Project Options
Parameters > Add Library or Object, but when I add the object files,
attempting to compile instead tells me that absolutely everything, from the
functions I tried to use to the functions I didn't try to use to main
itself, has been multiply defined. And, of course, it still has the same
linker error as before.
What am I doing wrong?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I apologize if I didn't include proper information - I, like a nub, omitted to
read the "READ THIS BEFORE POSTING YOUR QUESTION!" thread before posting my
question. My bad!
Now that I know where the compile log is in Dev C++, I can provide more useful
information. Such as:
The command send to the compiler is:
the only difference of which is that it has the required objects once, not
twice. So the problem, as I should have known, isn't that the object files
aren't being sent to g++ but... well, I don't know. Seems like it should be
linking, but I still have the problem where every llist function I try to use
has an undefined reference. Although, references to the constructor in
unit.cpp work fine... is it the order of linkage? Is it possible that's the
problem, and can I change that?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
And I am an idiot. Mentioned the problem to my dad, and was shortly reminded
that special consideration has to be taken into account for template classes.
Namely, I had the declarations in a different file from the definition.
So, never mind. Fixed it.
clonks head several times
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well done, and thanks for reporting back so no one wasted any time on it.
Note that when posting the log you should copy & paste the entire log
verbatim, (and without removing the line breaks), as it contains information
that may be useful in diagnosis (and the line breaks stop this forum from
adding the scroll bar!).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've been having a problem with the program I'm trying to code in Dev C++
4.9.9.2. I have main.cpp and main.h as the, well, main meat of the program,
with two classes (a data type and a keyed linked-list) each declared in their
own .h file and defined in their own .cpp file. Everything compiles to object
code quite nicely, but when I put references in main.cpp to functions defined
in one of the other .cpp files, it gives me a linker error saying that the
function was not defined.
I tried adding the object code to the project (under Project > Project Options
What am I doing wrong?
I apologize if I didn't include proper information - I, like a nub, omitted to
read the "READ THIS BEFORE POSTING YOUR QUESTION!" thread before posting my
question. My bad!
Now that I know where the compile log is in Dev C++, I can provide more useful
information. Such as:
The command send to the compiler is:
g++.exe -DDEBUG main.o unit.o llist.o -o "Weather.exe" -L"C:/Dev-Cpp/lib"
-mwindows ../../../../Dev-Cpp/lib/liballeg.a llist.o main.o unit.o -lgmon -pg
-g3
if I do include the object code in Project > Project Options > Parameters >
Add Library or Object.
g++.exe -DDEBUG main.o unit.o llist.o -o "Weather.exe" -L"C:/Dev-Cpp/lib"
-mwindows ../../../../Dev-Cpp/lib/liballeg.a -lgmon -pg -g3
the only difference of which is that it has the required objects once, not
twice. So the problem, as I should have known, isn't that the object files
aren't being sent to g++ but... well, I don't know. Seems like it should be
linking, but I still have the problem where every llist function I try to use
has an undefined reference. Although, references to the constructor in
unit.cpp work fine... is it the order of linkage? Is it possible that's the
problem, and can I change that?
And I am an idiot. Mentioned the problem to my dad, and was shortly reminded
that special consideration has to be taken into account for template classes.
Namely, I had the declarations in a different file from the definition.
So, never mind. Fixed it.
clonks head several times
Well done, and thanks for reporting back so no one wasted any time on it.
Note that when posting the log you should copy & paste the entire log
verbatim, (and without removing the line breaks), as it contains information
that may be useful in diagnosis (and the line breaks stop this forum from
adding the scroll bar!).