Using Borland C++ 3.1, I'm attempting to compile a small program
that should be testing my knowledge of VGA programming; however,
there's one line of code that's giving me trouble:
const float m = ( (x1-x) / (y1-y) ); //calculating slope using
//point-slope linear form
BCC will compile this with no problems, however, when I get around
to linking, I receive the following errors:
Error: Undefined symbol N_FTOL@ in module SCRNTST1.CPP
Error: Undefined symbol FIDRQQ in module SCRNTST1.CPP
Error: Undefined symbol FIWRQQ in module SCRNTST1.CPP
What are these symbols? They're not in float.h, and if I change "const
float" to "const int" the program links fine (although it doesn't run
with the desired effect, but I know why this is). Here's the rest of
the code in question:
Notes:
setMCGAMode() calls an assembler function which drops us in VGA mode 13h
setTextMode() restores default CRT mode (assembler).
setPixel(), getPixel() self-explanatory (assembler).
line() accepts two points (x,y) and (x1,y1), and draws a line
between them, using point-slope form: (y-y1) = m(x-x1). The fifth
(char) argument is a color value (one byte).
vgalib.hpp is where the prototypes for the graphics functions are, as
well as the function line(unsigned int, unsigned int, unsigned int,
unsigned int, char).
BEGIN CODE SEGMENT -----------------------------------------------------
***** scrntst1.cpp
#include <iostream.h>
#include <conio.h>
#include <time.h>
#include <stdlib.h>
// #include <float.h> // no help, though, even when included!
#include "vgalib.hpp"
int main() {
randomize();
cout << "Press any key to go into graphics mode ... ";
getch();
setMCGAMode();
for (signed int i = -15; i<15; i++) {
for (signed int j = -15; j<15; j++) {
setPixel(160+i, 100+j, random(256));
}
}
unsigned int color = getPixel(160, 99);
line(0,0,120,100,0xFF);
getch();
setTextMode();
cout << "Value at pixel 160, 99 was " << color << endl;
return 0;
}
***** end scrntst1.cpp
***** vgalib.hpp
#define ICE_VGALIB_HPP
extern "C" { // assembly routines
void setMCGAMode();
void setTextMode();
void setPixel(unsigned int, unsigned int, char);
char getPixel(unsigned int, unsigned int);
}
void line(unsigned int x, unsigned int y, unsigned int x1,
unsigned int y1, char color) {
const float m = ((x1-x)/(y1-y));
int currenty;
if (x < x1) {
for (int currentx = x; currentx <= x1; currentx++) {
currenty = ((0-m) * (currentx-x) + y);
setPixel(currentx, currenty, color);
}
}
if (x > x1) {
for (int currentx = x; currentx >= x1; currentx--) {
currenty = ((0-m) * (currentx-x) + y);
setPixel(currentx, currenty, color);
}
}
}
***** end vgalib.hpp
END CODE SEGMENT -------------------------------------------------------
Through the acclaimed method of trial and error, I've managed
to find that the line:
1: m = (float) ( (x1-x) / (y1-y) );
Produces the errors:
Error: Undefined symbol FIDRQQ in module SCRNTST1.CPP
Error: Undefined symbol FIWRQQ in module SCRNTST1.CPP
I found this by commenting out the function and adding it in
line-by-line. With this, everything but
2: float m = ((x1-x)/(y1-y));
is commented out. If I comment out line labeled "1:" and
assign m a value of (float) 3/4, and un-comment the rest of
the code (and use only the if(x>x1) statement), I get
the errors:
Error: Undefined symbol N_FTOL@ in module SCRNTST1.CPP
Error: Undefined symbol FIDRQQ in module SCRNTST1.CPP
However, this doesn't help. I've tried linking in the
maths.lib (small memory model math library), including
float.h, and including math.h, all to no avail.
Trying to link this produces the errors above. Again, including float.h
has no effect whatsoever. If anyone can point out what I'm doing wrong,
I'd be very grateful! Thanks in advance!
--
-|-E the Icefalcon
the floating point lib is not being linled in.
There is a command line parm to supress all floating point stuff, make sure it
isn't on.
Sample batch file that includes floating point stuff, large mem model
%1 is the 'main' object file and exe name. %2 is an optional second object file
tlink c:\borlandc\lib\c0l %1 %2, %1,, emu mathl cl.lib > lnk.out
type lnk.out
emu can be replaced with various libs, depending on if you want to assume a 387
(floating point unit) is available or not.
These days with 486's and pentiums you can pretty much assume there is a FPU and
replace emu with fp87
--
The AnArChIsT! Anarchy! Not! Chaos!
aka
Alex Russell
ale...@uniserve.com
Hi, Kouri no Taka !
This symbols are in FP87.LIB. You must build you program so:
bcc -c -ml scrntst1
tlink c:\bc31\lib\c0l scrntst1, scrntst1, , fp87 mathl cl ...[other libs]...
// for large memory model
/* Your turboc.cfg must contain /IC:\BC31\INCLUDE && your TLINK.CFG in
BC31\BIN directory must contain /LC:\BC31\LIB */
If you want to display float point values with printf or input with atof,
you must remember your program must contain line
#pragma extref _floatconvert // it placed in stdlib.h (?) - I don't
remember, where is
and don't change library file name order in call to tlink.
(I am working on BC++ 4.5)
Your troubles because BCC.EXE don't know, would you like to link FP library
to you program or not. It automaticly links only cl (cc, cs, ...) libraries
and you must link program manually.
Regards, Konstantin.