CVS version compiling error

Having trouble with the game? Report issues and get help here. Read this first!

Moderator: Forum Moderators

Forum rules
Before reporting issues in this section, you must read the following topic:
Post Reply
vynaldo
Posts: 9
Joined: September 18th, 2003, 9:16 am
Location: Australia
Contact:

CVS version compiling error

Post by vynaldo »

Code: Select all

g++ -O2 -Wall -I. -Isrc -Isrc/tools -Isrc/widgets `sdl-config --cflags` `freetype-config --cflags` -c src/playturn.cpp -o src/playturn.o
src/playturn.cpp: In function `void play_turn (game_data &, game_state
&, gamestatus &, config &, config *, CVideo &, CKey &, display &,
game_events::manager &, gamemap &, vector<team, allocator<team> > &,
int, map<gamemap::location, unit, less<gamemap::location>,
allocator<unit> > &)':
src/playturn.cpp:241: `round' undeclared (first use this function)
src/playturn.cpp:241: (Each undeclared identifier is reported only once
for each function it appears in.)
make: *** [src/playturn.o] Error 1
Any ideas?

I tried changing it to include math.h (is this the same as cmath?), but got the same error. So instead I removed the calls to round then it complied okay :)
miyo
Posts: 2201
Joined: August 19th, 2003, 4:28 pm
Location: Finland

Post by miyo »

Please give us a bit more information at least operating system and if GNU/Linux what is the distribution and version.

- Miyo
vynaldo
Posts: 9
Joined: September 18th, 2003, 9:16 am
Location: Australia
Contact:

Post by vynaldo »

hmm you're right- my original post was a bit vague... sorry...

more info:
  • redhat 7.3 on i386
    kernel 2.4.18-3
    gcc 2.96
    SDL 1.2.4
BTW 0.4.8 compiles fine.
fmunoz
Founding Artist
Posts: 1469
Joined: August 17th, 2003, 10:04 am
Location: Spain
Contact:

Post by fmunoz »

Seems that Dave forgot again to include a header file:-),
you can grep the header files to find where is "round"
or check other wesnoth source files where the function is called.
I'll check later at home :-)
vynaldo
Posts: 9
Joined: September 18th, 2003, 9:16 am
Location: Australia
Contact:

Post by vynaldo »

0.4.8 (which compiled fine) playturn.cpp uses ceil() 4 times. <cmath> is included at the top which defines this function.
  • 232: << int(ceil(100.0*stats.chance_to_hit_defender)) << "%";
    238: << int(ceil(100.0*stats.chance_to_hit_attacker)) << "%";
    682: const int resist=int(100.0-ceil(100.0*resistance));
    722: const int def = int(100.0-ceil(100.0*defense));
CVS@now (which doesn't compile) playturn.cpp has replaced this with round() 4 times.
  • 241: << int(round(100.0*stats.chance_to_hit_defender))<< "%";
    247: << int(round(100.0*stats.chance_to_hit_attacker))<< "%";
    699: const int resist = 100 - int(round(100.0*resistance));
    744: const int def = 100-int(round(100.0*defense));
My man pages tell me round() is defined in math.h but including this file still comes up with the same error.

I ran a grep and ceil() *is* defined in my cmath file but the *only* reference to round() is in tgmath.h which I don't know what is. Maybe my development environment is incomplete.....?
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Post by Dave »

The problem is that round() is only C99 standard, not C89 or C++98 standard, and so not included on some compilers. (Although the C99 standard is what? 4 whole years old now! You'd think most compilers would support it by now)

I have fixed the problem in CVS simply by defining our own version of round().

David
Post Reply