I’m merging a static library (assimp) into an existing project (Spring RTS) where both the library and the project are under regular development. I’m trying to add the library in such a way that I can easily repeat the integration as new releases come out.
Anyway, the issue is that Spring requires the library to perform all maths using the streflop maths library. In practice this means min(x,y) should be replaced with streflop::min(x,y) everywhere it is used (which is a lot, considering the issue applies to all maths functions).
I could do a mass regex replace but I was hoping for something a little more elegant. After some research and testing it seemed that adding using namespace streflop; at the top of each .cpp file would do the trick but it didn’t.
The exact error is:
/mnt/work/workspace/spring-patch-git/spring/rts/lib/assimp/code/FixNormalsStep.cpp:147: error: call of overloaded sqrtf(const float&) is ambiguous
/usr/include/bits/mathcalls.h:157: note: candidates are: float sqrtf(float)
/mnt/work/workspace/spring-patch-git/spring/rts/lib/streflop/SMath.h:347: note: streflop::Simple streflop::sqrtf(streflop::Simple)
I thought the whole point of namespaces was to resolve this kind of thing but it doesn’t seem to work here. I’m a bit confused by the reference to streflop::Simple as well. Is this a nested namespace and could that be part of the reason it isn’t working as expected?
If you only need the
minfunction from thestreflopnamespace, you can useinstead of
This will import only the name
min, not the whole namespace.Your error is because what you are doing imports every name from the
streflopnamespace so that they can be used unqualified, andsqrtfalready exists unqualified. Are you perhaps including C header files as they are in C? That is, usingmath.hinstead ofcmath? Because if you use the C++ headers likecmath, the functions from the standard library will be in thestdnamespace and you shouldn’t get a clash even if you import the wholestreflopnamespace.Another option is that if the places where you now get errors from are few, you can explicitly qualify them. Like in this case, you can replace
sqrtfwith eitherstreflop::sqrtfor::sqrtf, depending on which version you want to use.The
streflop::Simplehas little to do with your issue; it is just the parameter type and return value forstreflop::sqrtf. The only way it is involved is that in overload resolution it gets treated likefloatso that both of thesqrtffunctions listed are possible to call and the compiler cannot determine which one you meant.