[Dev-C++] linking error 'undefined reference'
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Gregor P. <pe...@in...> - 2002-01-07 00:04:44
|
=============================================================================
-----------------------------------------------------------------------------
THIS IS NOT AS MUCH TEXT AS IT SEEMS ON THE FIRST SIGHT!
THERE IS EVEN LESS CODE TO READ!
THIS POSTING IS JUST WELL STRUCTURED AND EXACTLY EXPLAINED
Make your viewer not braking the lines and it will be well
readable ...
GIVE IT A CHANCE ;-)
-----------------------------------------------------------------------------
=============================================================================
=============================================================================
--- you probably won't need this section ---
A little history/introduction
=============================================================================
I have this line of code in a file called 'lex.yy.c'
('command.cpp' is a self written C++ class which works well in different
programms so I suspect no error in here)
File: lex.yy.c
...
Command* tmpCommand = new Command();
...
which causes the following error:
scannerStr.cpp: In function `int yylex()':
scannerStr.cpp:121: `Command' undeclared (first use this function)
scannerStr.cpp:121: `tmpCommand' undeclared (first use this function)
so I add this include statement
#include <command.hpp>
to the corresponding header file 'lex.yy.h'.
The compiler seems to be satisfied now everything is fine so far
but between me an a runnung programm ist still the linker ...
=============================================================================
--- here comes the important part ---
And now to (something completly ... (no sorry it's just)) my problem
=============================================================================
My project-manger looks something like this:
-+ Scanner
|- lex.yy.c
|- lex.yy.h
|- scanner.c
As said the compiling works fine but the linker is complaining about
some 'undefined reference'(s): (btw: what's that?)
The exact error messages are:
c:\scanner\devcpp\lex.yy.o(.text+0x5ed):lex.yy.c: undefined reference to
`Command::Command(void)'
c:\scanner\devcpp\lex.yy.o(.text+0x2c18):lex.yy.c: undefined reference to
`yy_flex_alloc(unsigned int)'
c:\scanner\devcpp\lex.yy.o(.text+0x2c4f):lex.yy.c: undefined reference to
`yy_flex_alloc(unsigned int)'
c:\scanner\devcpp\lex.yy.o(.text+0x2e2d):lex.yy.c: undefined reference to
`yy_flex_alloc(unsigned int)'
c:\scanner\devcpp\lex.yy.o(.text+0x2f7f):lex.yy.c: undefined reference to
`yy_flex_alloc(unsigned int)'
=============================================================================
--- this may be a hint to the solution ---
the funny thing
=============================================================================
Without knowing what and why I did
I added the files:
command.cpp and
command.hpp
to the current scanner-project which expanded the project-manager
like this:
-+ Scanner
|- command.cpp
|- command.hpp
|- lex.yy.c
|- lex.yy.h
|- scanner.c
Adding the class command to the project make the first error dissapear:
c:\scanner\devcpp\lex.yy.o(.text+0x2c18):lex.yy.c: undefined reference to
`yy_flex_alloc(unsigned int)'
c:\scanner\devcpp\lex.yy.o(.text+0x2c4f):lex.yy.c: undefined reference to
`yy_flex_alloc(unsigned int)'
c:\scanner\devcpp\lex.yy.o(.text+0x2e2d):lex.yy.c: undefined reference to
`yy_flex_alloc(unsigned int)'
c:\scanner\devcpp\lex.yy.o(.text+0x2f7f):lex.yy.c: undefined reference to
`yy_flex_alloc(unsigned int)'
But why?
I tried to compare the make files and but I can't discover any
difference (ecxept of the 'command.o' file of course)... .
Can anybody give me some background knowledge about the linking process?
=============================================================================
--- just answer this and I will be happy ---
What makes a 'reference' defined while adding 'command' to the poject?
Is there a compiler/linker-option which does the same?
Does this (hopefully existing) option do the same for the
other 'undefined references'?
What do I have to add to the project (lex.yy.c is it already) to get
those 'references' defined?
=============================================================================
ANY help is wellcome!!!
In hope of helpful hints
Gregor (pe...@in...)
|