Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undeclared identifier isfinite when compiling with GCC 5.4 stdlib #509

Closed
chrahunt opened this issue Jul 4, 2018 · 5 comments
Closed

Undeclared identifier isfinite when compiling with GCC 5.4 stdlib #509

chrahunt opened this issue Jul 4, 2018 · 5 comments

Comments

@chrahunt
Copy link

chrahunt commented Jul 4, 2018

Test script

#!/bin/sh
if [ ! -d Box2D ]; then
    git clone https://github.com/erincatto/Box2D.git
fi
cat <<EOF > main.cpp
#include <math.h>
#include <cmath>
#include "Box2D/Box2D/Box2D.h"

int main(int argc, char** argv) {}
EOF
g++ --version
g++ -std=c++11 -IBox2D main.cpp

Test output

$ ./test.sh
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

In file included from Box2D/Box2D/Common/b2Draw.h:22:0,
                 from Box2D/Box2D/Box2D.h:35,
                 from main.cpp:3:
Box2D/Box2D/Common/b2Math.h: In function ‘bool b2IsValid(float32)’:
Box2D/Box2D/Common/b2Math.h:28:19: error: ‘isfinite’ was not declared in this scope
  return isfinite(x);
                   ^
Box2D/Box2D/Common/b2Math.h:28:19: note: suggested alternative:
In file included from main.cpp:2:0:
/usr/include/c++/5/cmath:601:5: note:   ‘std::isfinite’
     isfinite(_Tp __x)
     ^

Under GCC 5.4 cmath in the gcc standard library undefs isfinite but does not provide the corresponding global function. You can see additional discussion on a similar issue in swig/swig#615.

Godbolt for quick reference showing compilation failure on GCC 5.4 but not other compilers/platforms. The important part is actually the stdlib in use as opposed to the compiler, as I discovered this while using clang with the stdlib on my platform (Ubuntu 16.04.3).

@erincatto
Copy link
Owner

Do you have a fix? I'm not running Linux.

@mightymos
Copy link

mightymos commented Jul 24, 2018

I also had a similar compilation failure/error message, but was able to fix by replacing the offending line in "b2Math.h" with:

return std::isfinite(x);

Compiler version is [g++ (tdm-1) 5.1.0] on Windows 7 64-bit.
This example prompted the fix:
https://en.cppreference.com/w/cpp/numeric/math/isfinite

EDIT: this might not be the correct fix...will check out further.

@mightymos
Copy link

mightymos commented Jul 24, 2018

This compiles and links with the changes to "b2Math.h":

#ifndef B2_MATH_H
#define B2_MATH_H

#include "Box2D/Common/b2Settings.h"
//#include <math.h>
#include <cmath>

/// This function is used to ensure that a floating point number is not a NaN or infinity.
inline bool b2IsValid(float32 x)
{
	return std::isfinite(x);
}

@jrmclaugh
Copy link

Also occurs while cross compiling for ARM using:
gcc version 7.3.0 (Ubuntu/Linaro 7.3.0-27ubuntu1~18.04)

The above workaround from mightymos allows it to compile and run successfully.

mlomb added a commit to mlomb/Box2D that referenced this issue Oct 26, 2019
waterimp added a commit to waterimp/box2d that referenced this issue Jan 10, 2020
@erincatto
Copy link
Owner

Currently building fine on Linux via travis-ci.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants