Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Thor 2.0 cmake build error OS X 10.7  (Read 24587 times)

0 Members and 1 Guest are viewing this topic.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Thor 2.0 cmake build error OS X 10.7
« Reply #45 on: September 07, 2012, 09:13:26 am »
Yes, it seems there is something going wrong with non basic types. However, I found a solution that seems to work :

#include <functional>
#include <type_traits>
#include <string>

template <typename T>
class Distribution {
    typedef std::function<T()> FactoryFn;

public:
//    template <typename U, class = typename std::enable_if<std::is_convertible<U, T>::value>::type>
//    Distribution(U cst)
    template <typename U>
    Distribution(U cst, typename std::enable_if<std::is_convertible<U, T>::value>::type* = 0)
    : m_factory()
    {
        T copy = cst;
//        m_factory = [copy] () { return copy; }; // FIX : replace this line
        m_factory = [cst] () { return cst; }; // with this one.
    }

private:
    FactoryFn m_factory;
};

struct Foo {
    char c, d;
    Foo() : c(0), d(0) { }
    Foo(char c, char d) : c(c), d(d) { }
};

struct Bar {
    char c, d;
    Bar() : c(0), d(0) { }
    Bar(char c, char d) : c(c), d(d) { }
    Bar(Bar const& bar) : c(bar.c), d(bar.d) { }
    Bar(Bar && bar) : c(std::move(bar.c)), d(std::move(bar.d)) { }
    Bar& operator=(Bar const bar) { c = bar.c; d = bar.d; return *this; }
    Bar& operator=(Bar && bar) { c = std::move(bar.c); d = std::move(bar.d); return *this; }
    ~Bar() { }
};

int main(int argc, const char * argv[])
{
    char someChar = 58;
    Distribution<int> distInt(someChar);

    std::string someString = "42";
//    Distribution<int> distInt2(someString); // Error, no matching ctor (as expected), no crash here

    Distribution<std::string> distStr(someString); // _WAS_ CRASHING HERE

    Distribution<float> distFloat(3.f);
    Distribution<double> distDouble(3.0);


    Foo someFoo = {'a', 'A'};
    Distribution<Foo> distFoo(someFoo); // _WAS_ CRASHING HERE

    Bar someBar = {'b', 'B'};
    Distribution<Bar> distBar(someBar); // _WAS_ CRASHING HERE

    [someBar]() { return someBar; }();

    return 0;
}
 

As you can see, before the fix, only basic types like int or double worked. Now, if we apply the fix everything works fine.

I test it out on Thor and clang doesn't crash anymore.  :)

Replace line 68 with
mFactory = [constant] () { return constant; };
and remove line 67 as it's no longer needed.
SFML / OS X developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Thor 2.0 cmake build error OS X 10.7
« Reply #46 on: September 07, 2012, 09:22:39 am »
Previously I said there were error in Random.cpp. Here is the log :
[  4%] Building CXX object src/CMakeFiles/thor.dir/Random.cpp.o
In file included from /Users/hiura/Prog/Libraries/C++/SFML extra/Thor/git/Thor/src/Random.cpp:30:
In file included from /usr/bin/../lib/c++/v1/random:1641:
/usr/bin/../lib/c++/v1/algorithm:2510:54: error: no member named '_Max' in
      'thor::<anonymous>::Engine'
    static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min
                                            ~~~~~~~~~^
/usr/bin/../lib/c++/v1/algorithm:2681:41: note: in instantiation of template class
      'std::__1::__independent_bits_engine<thor::<anonymous>::Engine, unsigned int>' requested here
        return static_cast<result_type>(_Eng(__g, _Dt)());
                                        ^
/usr/bin/../lib/c++/v1/algorithm:2647:17: note: in instantiation of function template specialization
      'std::__1::uniform_int_distribution<int>::operator()<thor::<anonymous>::Engine>' requested
      here
        {return (*this)(__g, __p_);}
                ^
/Users/hiura/Prog/Libraries/C++/SFML extra/Thor/git/Thor/src/Random.cpp:119:21: note: in
      instantiation of function template specialization
      'std::__1::uniform_int_distribution<int>::operator()<thor::<anonymous>::Engine>' requested
      here
        return distribution(globalEngine);
                           ^
In file included from /Users/hiura/Prog/Libraries/C++/SFML extra/Thor/git/Thor/src/Random.cpp:30:
/usr/bin/../lib/c++/v1/random:3524:51: error: no member named '_Max' in 'thor::<anonymous>::Engine'
    const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value;
                                           ~~~~~~~^
/usr/bin/../lib/c++/v1/random:3655:11: note: in instantiation of function template specialization
      'std::__1::generate_canonical<float, 24, thor::<anonymous>::Engine>' requested here
        * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g)
          ^
/usr/bin/../lib/c++/v1/__config:266:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
              ^
/usr/bin/../lib/c++/v1/random:3619:17: note: in instantiation of function template specialization
      'std::__1::uniform_real_distribution<float>::operator()<thor::<anonymous>::Engine>' requested
      here
        {return (*this)(__g, __p_);}
                ^
/Users/hiura/Prog/Libraries/C++/SFML extra/Thor/git/Thor/src/Random.cpp:132:21: note: in
      instantiation of function template specialization
      'std::__1::uniform_real_distribution<float>::operator()<thor::<anonymous>::Engine>' requested
      here
        return distribution(globalEngine);
                           ^
In file included from /Users/hiura/Prog/Libraries/C++/SFML extra/Thor/git/Thor/src/Random.cpp:30:
/usr/bin/../lib/c++/v1/random:3526:34: error: no member named '_Max' in 'thor::<anonymous>::Engine'
    const _RealType _Rp = _URNG::_Max - _URNG::_Min + _RealType(1);
                          ~~~~~~~^
/usr/bin/../lib/c++/v1/random:3528:36: error: no member named '_Min' in 'thor::<anonymous>::Engine'
    _RealType _Sp = __g() - _URNG::_Min;
                            ~~~~~~~^
4 errors generated.
 

However, defining THOR_USE_STD_RANDOMENGINE solves that, i.e. adding -DTHOR_USE_STD_RANDOMENGINE to CMAKE_CXX_FLAGS.
SFML / OS X developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0 cmake build error OS X 10.7
« Reply #47 on: September 07, 2012, 09:25:52 am »
Replace line 68 with
mFactory = [constant] () { return constant; };
and remove line 67 as it's no longer needed.

You didn't read the comment :P
// Convert to T first to avoid conversion happening at every function call.

But I think I can use a classical functor instead. Can you submit a bug report? Even if it takes a year, it's better than nothing ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Thor 2.0 cmake build error OS X 10.7
« Reply #48 on: September 07, 2012, 10:43:05 am »
Yep, I missed that one  ::)

Bug reported.

Ho, and after compiling SFML with -stdlib=libc++, everything work!
SFML / OS X developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0 cmake build error OS X 10.7
« Reply #49 on: September 07, 2012, 03:13:36 pm »
I pushed the Distribution workaround.


error: no member named '_Max' in 'thor::<anonymous>::Engine'
error: no member named '_Min' in 'thor::<anonymous>::Engine'
_Max() and _Min() are not required for random number engines by the standard. The methods are called min() and max(), which I have implemented.

Another bug in libc++...


Ho, and after compiling SFML with -stdlib=libc++, everything work!
With the newest Thor revision, what changes are necessary to compile successfully? Only a #define THOR_USE_STD_RANDOMENGINE?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: Thor 2.0 cmake build error OS X 10.7
« Reply #50 on: September 07, 2012, 03:45:19 pm »
With the newest Thor revision, what changes are necessary to compile successfully? Only a #define THOR_USE_STD_RANDOMENGINE?
Yes :) .
Want to play movies in your SFML application? Check out sfeMovie!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0 cmake build error OS X 10.7
« Reply #51 on: September 07, 2012, 04:11:48 pm »
Okay, fix implemented and pushed. I hope it's the last one for the moment :D
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: Thor 2.0 cmake build error OS X 10.7
« Reply #52 on: September 07, 2012, 04:15:51 pm »
You removed the -stdlib=libc++, it doesn't work without it:
Code: [Select]
/Users/ceylo/Development/Thor/extlibs/aurora/include/Aurora/Tools/Metaprogramming.hpp:31:10: fatal error: 'type_traits' file not found
#include <type_traits>
         ^
1 error generated.

There's no other C++11 standard library installed so you have to specify libc++ if you want support for C++11.
Want to play movies in your SFML application? Check out sfeMovie!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0 cmake build error OS X 10.7
« Reply #53 on: September 07, 2012, 04:50:13 pm »
Oh, this was not my intention, it's corrected now.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: Thor 2.0 cmake build error OS X 10.7
« Reply #54 on: September 07, 2012, 05:02:17 pm »
Everything builds fine now :)

There's only this warning remaining (FYI only):
Code: [Select]
/Users/ceylo/Development/Thor/src/ActionOperations.cpp:63:11: warning: 17 enumeration values not handled in switch: 'Closed', 'Resized',
      'TextEntered'... [-Wswitch]
                switch (event.type)
                        ^
1 warning generated.
Want to play movies in your SFML application? Check out sfeMovie!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0 cmake build error OS X 10.7
« Reply #55 on: September 07, 2012, 05:09:00 pm »
Yes, I also got it on Windows. I find the warning a little bit questionable, I don't want to write an empty default branch everytime I handle only some of the cases. But maybe it would be better practice, in case an enumerator is really forgotten.

Apart from that, I'm really glad it works now. Great thanks to both of you (Ceylo and Hiura) for helping me with feedback and testing Thor on Mac! :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: