tags:

views:

394

answers:

2

Do streflop or boost libraries change the definition of std::min?

I have a project that compiles fine with g++/make UNTIL I merge it with the CMake build of another project (using add_directory). Suddenly I get:

no matching function for call to min(double&,float)

The line number it claims the error is on is wrong (it's pointing to the last line of the source file) but I'm going to assume the relevant code is this:

first = std::min (first, key.mTime);

Where first is declared as a double.

The 'parent' project (Spring RTS) uses boost and streflop but even after replacing all includes for <math.h> with "streflop_cond.h" in the child project (assimp) the problem remains.

Maybe some compiler flags are responsible, I'm not sure. An theories would be appreciated. The source for both projects are available online.

I've spent nearly 7 hours on this now and I don't seem any closer to a solution.

The full error and build flags is:

    [ 61%] Building CXX object rts/lib/assimp/code/CMakeFiles/assimp.dir/ScenePreprocessor.cpp.o
cd /mnt/work/workspace/spring-patch-git/linux/build/rts/lib/assimp/code && /usr/bin/g++   -Dassimp_EXPORTS -DSYNCCHECK -DNO_AVI -DSPRING_DATADIR=\"/usr/local/share/games/spring\" -DSTREFLOP_SSE -DASSIMP_BUILD_DLL_EXPORT -msse -mfpmath=sse -fsingle-precision-constant -frounding-math -mieee-fp -pipe -fno-strict-aliasing -fvisibility=hidden -fvisibility-inlines-hidden -pthread  -O0 -Wall -Wno-sign-compare -DDEBUG -D_DEBUG -DNO_CATCH_EXCEPTIONS -gstabs -fPIC -I/mnt/work/workspace/spring-patch-git/spring/rts/System -I/mnt/work/workspace/spring-patch-git/spring/rts/lib/lua/include -I/mnt/work/workspace/spring-patch-git/spring/rts/lib/streflop -I/usr/include/SDL -I/usr/include/boost-1_39 -I/mnt/work/workspace/spring-patch-git/spring/rts -I/usr/include/AL -I/usr/include/freetype2 -I/mnt/work/workspace/spring-patch-git/spring/rts/lib/assimp/include -I/mnt/work/workspace/spring-patch-git/spring/rts/lib/assimp/../streflop   -o CMakeFiles/assimp.dir/ScenePreprocessor.cpp.o -c /mnt/work/workspace/spring-patch-git/spring/rts/lib/assimp/code/ScenePreprocessor.cpp
/mnt/work/workspace/spring-patch-git/spring/rts/lib/assimp/code/ScenePreprocessor.cpp: In member function void Assimp::ScenePreprocessor::ProcessAnimation(aiAnimation*):
/mnt/work/workspace/spring-patch-git/spring/rts/lib/assimp/code/ScenePreprocessor.cpp:280: error: no matching function for call to min(double&, float)
make[2]: *** [rts/lib/assimp/code/CMakeFiles/assimp.dir/ScenePreprocessor.cpp.o] Error 1
+3  A: 

Try

std::min<double>(first, key.mTime);

The two arguments seem to have different types so the compiler can't resolve the template argument to std::min

EDIT3: I actually took a look at the assimp library and from your error message, it's line 280 of ScenePreprocessor.cpp that's the cause of the problems:

anim->mDuration = last - std::min( first, 0. );

There's nothing wrong with this line however, first is declared as a double and 0. means a zero double literal.

I would guess that the problem lies in the STREFLOP library, it seems like it's incorrectly interpreting 0. as a float literal.

Andreas Brinck
Or `<double>`, which is probably desired here.
Roger Pate
@Roger Thanks, updated
Andreas Brinck
Just a guess, but it may be that the code defining mTime relies on a preprocessor symbol to decide whether to use floats or doubles. The compiler options may define this symbol differently in the two cases.
James Hopkin
the problem with solving this via casts is that i'm trying to touch the source as little as possible. The assimp library is quite young and I expect to be pulling in new versions fairly regularly. Solving this via project options or global header changes is preferable to tracking down each affected line individually.
SpliFF
@SpliFF See my edited answer.
Andreas Brinck
You could rewrite your code to be a specialization instead... but it's still highly dubious. It's still possible there's another cause for the behavior SpliFF is seeing, too.
Roger Pate
@Roger Can you really make a specialization of this? Could you type it up at codepad.org and show me? As for there being another cause I don't think so, from the error message it's obvious that the two arguments have different type (there may be other errors as well of course...)
Andreas Brinck
@SpliFF See my new edited answer ;)
Andreas Brinck
Andreas: Ah, you're right, because it mandates the same type, you can't change that.
Roger Pate
Thanks Andreas. You were 90% correct. I had the wrong line and the constant was being changed to a float, rather than a double. The culprit wasn't streflop though, it was the compiler flag `-fsingle-precision-constant` about which the GCC manual says "Treat floating point constant as single precision constant instead of implicitly converting it to double precision constant.". I'd still rather not put in casts but I may be able to disable this flag during the assimp build. The flag is used by Spring to help guarantee consistent maths across platforms/hardware.
SpliFF
Oh, and thank you for being thorough enough to chase down the code. I wish I could donate extra points just for that. You're a life-saver.
SpliFF
A: 

Could this error be related to min() being a template and expecting parameters to be of the same type? The error message suggests you are putting a double and a float into it.
While this doesn't answer your question if min() is redefined, it may help with the compiling problem.

mxp