Board index FlightGear Support Compiling

[SOLVED] isnan problem while compiling simgear

Building FlightGear from source, and in the need for help?

Re: isnan problem while compiling simgear

Postby mifi » Thu Oct 27, 2016 5:57 pm

Nope. Exactly the same error, and the same lines in CMakeCache.txt.
mifi
 
Posts: 327
Joined: Mon Jul 23, 2007 4:24 pm
Location: NL
Version: git next
OS: Ubuntu 18.04.x Gnome

Re: isnan problem while compiling simgear

Postby mifi » Thu Oct 27, 2016 8:18 pm

Perhaps this helps?
I found this is compilation_log.txt:

Code (): Select all
-- Performing Test HAVE_ISNAN
-- Performing Test HAVE_ISNAN - Success
-- Performing Test HAVE_STD_ISNAN
-- Performing Test HAVE_STD_ISNAN - Success


It seems both get defined.

Regards
Michiel
mifi
 
Posts: 327
Joined: Mon Jul 23, 2007 4:24 pm
Location: NL
Version: git next
OS: Ubuntu 18.04.x Gnome

Re: isnan problem while compiling simgear

Postby mifi » Thu Oct 27, 2016 8:25 pm

Here is another snippet.
I found this in build/simgear/simgear/CMakeFiles/CMakeOutput.log at line 809:

Code (): Select all
Source file was:
#include <cmath>
int main() { return isnan(0.0);}
Performing C++ SOURCE FILE Test HAVE_STD_ISNAN succeeded with the following output:
Change Dir: /home/mifi/Software/Sources/fgfs53/next/build/simgear/CMakeFiles/CMakeTmp


And this in the same file at line 795, i.e. earlier:

Code (): Select all
Performing C++ SOURCE FILE Test HAVE_ISNAN succeeded with the following output:
Change Dir: /home/mifi/Software/Sources/fgfs53/next/build/simgear/CMakeFiles/CMakeTmp


Is there anything else I can do to help?
Regards,
Michiel
mifi
 
Posts: 327
Joined: Mon Jul 23, 2007 4:24 pm
Location: NL
Version: git next
OS: Ubuntu 18.04.x Gnome

Re: isnan problem while compiling simgear

Postby rominet » Thu Oct 27, 2016 10:03 pm

It's puzzling. mifi, can you paste the start of your simgear/sound/soundmgr_openal_private.hxx at least until the line containing:
Code: Select all
#include <cmath>

and make really really sure this file is used in your compilation (for instance by writing garbage inside and trying to build)? Because according to your cmake tests, plain isnan() should work as soon as there is a #include <cmath>... Can you try moving the #include <cmath> line at the end of all includes?
rominet
 
Posts: 605
Joined: Sat Nov 01, 2014 2:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Re: isnan problem while compiling simgear

Postby mifi » Fri Oct 28, 2016 7:35 am

I will do that today and get back to you.
mifi
 
Posts: 327
Joined: Mon Jul 23, 2007 4:24 pm
Location: NL
Version: git next
OS: Ubuntu 18.04.x Gnome

Re: isnan problem while compiling simgear

Postby mifi » Fri Oct 28, 2016 7:43 am

My soundmgr_openal_private.hxx, this first part...
Note, by the way, the typo in the first line in 'prviate'.

Code (): Select all
// soundmgr_openal_prviate.hxx -- Implementation details of the soung manager
//
// Sound manager initially written by David Findlay
// <david_j_findlay@yahoo.com.au> 2001
//
// C++-ified by Curtis Olson, started March 2001.
// Modified for the new SoundSystem by Erik Hofman, October 2009
//
// Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt
// Copyright (C) 2009 Erik Hofman <erik@ehofman.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$


#ifndef _SG_SOUNDMGR_OPENAL_PRIVATE_HXX
#define _SG_SOUNDMGR_OPENAL_PRIVATE_HXX 1

#ifdef HAVE_CONFIG_H
# include <simgear_config.h>
#endif

#include <string>
#include <vector>
#include <cmath>
#include <map>


The other experiments will follow shortly.

Cheers
Michiel
mifi
 
Posts: 327
Joined: Mon Jul 23, 2007 4:24 pm
Location: NL
Version: git next
OS: Ubuntu 18.04.x Gnome

Re: isnan problem while compiling simgear

Postby mifi » Fri Oct 28, 2016 7:54 am

Ok.
I introduced rubbish in soundmgr_openal_private.hxx and the compiler generated a fault (complaining about 'rubbish'), so I verfied that I am changing the actual source that is used to compile.

I moved the cmath include to the end of the includes, like so:

Code (): Select all
#ifndef _SG_SOUNDMGR_OPENAL_PRIVATE_HXX
#define _SG_SOUNDMGR_OPENAL_PRIVATE_HXX 1

#ifdef HAVE_CONFIG_H
# include <simgear_config.h>
#endif

#include <string>
#include <vector>
#include <map>

#if defined(__APPLE__)
# include <OpenAL/al.h>
# include <OpenAL/alc.h>
#elif defined(OPENALSDK)
# include <al.h>
# include <alc.h>
#else
# include <AL/al.h>
# include <AL/alc.h>
#endif

#include <simgear/structure/SGSharedPtr.hxx>
#include <cmath>

#if defined(HAVE_STD_ISNAN) && !defined(HAVE_ISNAN)
using std::isnan;
#endif
class SGSampleGroup;


And the result is still the same:

Code (): Select all
/home/mifi/Software/Sources/fgfs53/next/simgear/simgear/sound/soundmgr_openal_private.hxx:76:22: error: ‘isnan’ was not declared in this scope
return (isnan(v[0]) || isnan(v[1]) || isnan(v[2]));


Sorry.
Regards
Michiel
mifi
 
Posts: 327
Joined: Mon Jul 23, 2007 4:24 pm
Location: NL
Version: git next
OS: Ubuntu 18.04.x Gnome

Re: isnan problem while compiling simgear

Postby mifi » Fri Oct 28, 2016 8:09 am

As a further experiment, I changed soundmgr_openal_private.hxx:

from
Code (): Select all
#if defined(HAVE_STD_ISNAN) && !defined(HAVE_ISNAN)
using std::isnan;
#endif


into

Code (): Select all
// #if defined(HAVE_STD_ISNAN) && !defined(HAVE_ISNAN)
#if defined(HAVE_STD_ISNAN)
using std::isnan;
#endif


That worked.
I can not oversee the consequences of not explicitly testing the undefinedness of HAVE_ISNAN, but it seems they are not mutually exclusive.

There is only one other test of HAVE_STD_ISNAN in simgear and it is in math/SGMisc.hxx, but phrased differently, as follows:

Code (): Select all
#ifdef HAVE_STD_ISNAN
return std::isnan(v);
#elif defined HAVE_ISNAN
return (isnan(v) != 0);
#else
// Use that every compare involving a NaN returns false
// But be careful, some usual compiler switches like for example
// -fast-math from gcc might optimize that expression to v != v which
// behaves exactly like the opposite ...
return !(v == v);
#endif


Here the test on HAVE_ISNAN is done only after the test for HAVE_STD_ISNAN has failed.

Michiel
mifi
 
Posts: 327
Joined: Mon Jul 23, 2007 4:24 pm
Location: NL
Version: git next
OS: Ubuntu 18.04.x Gnome

Re: isnan problem while compiling simgear

Postby rominet » Fri Oct 28, 2016 9:23 am

Thank you for the detailed reports. Your last experiment:
Code: Select all
// #if defined(HAVE_STD_ISNAN) && !defined(HAVE_ISNAN)
#if defined(HAVE_STD_ISNAN)
using std::isnan;
#endif

is just a variant of what Edward (bugman) made you try earlier (removing the test and unconditionally using 'using std::isnan;'). It simply confirms that std::isnan() is available to your compiler and linker.

But according to the SimGear tests you posted, plain isnan() should be available too, thus the code should also work without 'using std::isnan;'. My impression is that there is a CMake problem, namely the
Code: Select all
check_cxx_source_compiles(
    "#include <cmath>
    int main() { return std::isnan(0.0);} "
    HAVE_STD_ISNAN)

test in the top-level CMakeLists.txt being compiled in different conditions than soundmgr_openal_private.hxx. This looks similar to https://cmake.org/Bug/view.php?id=15361 so you could try the workaround given there: add
Code: Select all
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")

before the
Code: Select all
check_cxx_source_compiles(
    "#include <cmath>
    int main() { return std::isnan(0.0);} "
    HAVE_STD_ISNAN)

test.

Another possibility would be to add:
Code: Select all
#include <simgear/math/SGMisc.hxx>

in simgear/sound/soundmgr_openal_private.hxx after
Code: Select all
#include <simgear/structure/SGSharedPtr.hxx>

and replace
Code: Select all
inline bool isNaN(float *v) {
   return (isnan(v[0]) || isnan(v[1]) || isnan(v[2]));
}

with:
Code: Select all
inline bool isNaN(float *v) {
   return (SGMisc::isNaN(v[0]) || SGMisc::isNaN(v[1]) || SGMisc::isNaN(v[2]));
}

or even:
Code: Select all
inline bool isNaN(float *v) {
   return (SGMisc<float>::isNaN(v[0]) || SGMisc<float>::isNaN(v[1]) || SGMisc<float>::isNaN(v[2]));
}

but this would only work by side effect of using std::isnan() because HAVE_STD_ISNAN is defined, the check in simgear/math/SGMisc.hxx being:
Code: Select all
#ifdef HAVE_STD_ISNAN
    return std::isnan(v);
#elif defined HAVE_ISNAN
    return (isnan(v) != 0);
#else
    ...
#endif

Good luck! :wink:
rominet
 
Posts: 605
Joined: Sat Nov 01, 2014 2:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Re: isnan problem while compiling simgear

Postby bugman » Fri Oct 28, 2016 9:25 am

bugman
Moderator
 
Posts: 1808
Joined: Thu Mar 19, 2015 10:01 am
Version: next

Re: isnan problem while compiling simgear

Postby mifi » Fri Oct 28, 2016 10:17 am

Thank you rominet and Edward (bugman).
I appreciate all the help.

I added the
Code (): Select all
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")

in CMakeLists.txt but that produced an error:
Code (): Select all
c++: error: unrecognized command line option ‘-stdlib=libc++’

Without the '-stdlib=libc++' I got the isnan problem again.

For the time being, I have a workaround by changing a line in soundmgr_openal_private.hxx, so I can fly 8)

I assume I will not be the only one with this particular problem, because I am running a normal Ubuntu 16.04.01 distro.
I am willing to help find a definitive solution. I am here if anybody needs further investigation.

Regards
Michiel
mifi
 
Posts: 327
Joined: Mon Jul 23, 2007 4:24 pm
Location: NL
Version: git next
OS: Ubuntu 18.04.x Gnome

Re: isnan problem while compiling simgear

Postby rominet » Fri Oct 28, 2016 10:27 am

Then just try with -std=c++11 but without -stdlib=libc++. The latter might be a MacOS thing. And you didn't try the things I proposed with SGMisc?
rominet
 
Posts: 605
Joined: Sat Nov 01, 2014 2:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Re: isnan problem while compiling simgear

Postby mifi » Fri Oct 28, 2016 10:36 am

I tried without the '-stdlib=libc++', rominet, but that results in the same isnan errors.

The SGMisc stuff I did not try. Do you want me to check if that is a suitable solution, in which case I will try that later today?
Or did you mean to provide me with a workaround?

Michiel
mifi
 
Posts: 327
Joined: Mon Jul 23, 2007 4:24 pm
Location: NL
Version: git next
OS: Ubuntu 18.04.x Gnome

Re: isnan problem while compiling simgear

Postby rominet » Fri Oct 28, 2016 10:37 am

Erik committed the SGMisc-based workaround (should work by lucky side effect if I'm right). Thus you can just update SG and retry.
rominet
 
Posts: 605
Joined: Sat Nov 01, 2014 2:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Re: isnan problem while compiling simgear

Postby mifi » Fri Oct 28, 2016 10:50 am

I noticed, yes. Thanks.
Compiling as we speak.

EDIT: and it is fine.

Michiel
mifi
 
Posts: 327
Joined: Mon Jul 23, 2007 4:24 pm
Location: NL
Version: git next
OS: Ubuntu 18.04.x Gnome

PreviousNext

Return to Compiling

Who is online

Users browsing this forum: No registered users and 2 guests