Compile-time error when using TGUI

Started by Dnake, 15 December 2015, 10:00:25

Dnake

Hi texus,

I downloaded the latest snapshots of TGUI and SFML on Github and I installed them by running the following commands:

mkdir build
cd build
cmake ..
make -j2
sudo make install
sudo ldconfig #Just to be sure

And then I wrote a very simple program, like this:

#include <TGUI/Label.hpp>
int main(){}

and I compiled it with g++ -std=c++11 -ltgui -lsfml-graphics -lsfml-window -lsfml-system main.cpp
But g++ does not think in that way, and say to me:

In file included from /usr/local/include/TGUI/Label.hpp:30:0,
                 from main.cpp:1:
/usr/local/include/TGUI/ClickableWidget.hpp:90:29: error: ‘virtual tgui::Widget::Ptr tgui::ClickableWidget::clone()’ marked ‘override’, but does not override
         virtual Widget::Ptr clone() override
                             ^
In file included from main.cpp:1:0:
/usr/local/include/TGUI/Label.hpp:99:22: error: ‘virtual void tgui::Label::setPosition(const tgui::Layout&)’ marked ‘override’, but does not override
         virtual void setPosition(const Layout& position) override;
                      ^
/usr/local/include/TGUI/Label.hpp:118:22: error: ‘virtual void tgui::Label::setSize(const tgui::Layout&)’ marked ‘override’, but does not override
         virtual void setSize(const Layout& size) override;
                      ^
/usr/local/include/TGUI/Label.hpp:329:22: error: ‘virtual void tgui::Label::initialize(tgui::Container*)’ marked ‘override’, but does not override
         virtual void initialize(Container *const container) override;
                      ^
/usr/local/include/TGUI/Label.hpp:354:22: error: ‘virtual void tgui::Label::update()’ marked ‘override’, but does not override
         virtual void update() override;
                      ^
In file included from /usr/include/x86_64-linux-gnu/c++/5/bits/c++allocator.h:33:0,
                 from /usr/include/c++/5/bits/allocator.h:46,
                 from /usr/include/c++/5/string:41,
                 from /usr/local/include/TGUI/Exception.hpp:30,
                 from /usr/local/include/TGUI/Global.hpp:32,
                 from /usr/local/include/TGUI/Widget.hpp:30,
                 from /usr/local/include/TGUI/ClickableWidget.hpp:30,
                 from /usr/local/include/TGUI/Label.hpp:30,
                 from main.cpp:1:
/usr/include/c++/5/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = tgui::ClickableWidget; _Args = {tgui::ClickableWidget&}; _Tp = tgui::ClickableWidget]’:
/usr/include/c++/5/bits/alloc_traits.h:256:4:   required from ‘static std::_Require<typename std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::type> std::allocator_traits<_Alloc>::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = tgui::ClickableWidget; _Args = {tgui::ClickableWidget&}; _Alloc = std::allocator<tgui::ClickableWidget>; std::_Require<typename std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::type> = void]’
/usr/include/c++/5/bits/alloc_traits.h:402:16:   required from ‘static decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) std::allocator_traits<_Alloc>::construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = tgui::ClickableWidget; _Args = {tgui::ClickableWidget&}; _Alloc = std::allocator<tgui::ClickableWidget>; decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) = <type error>]’
/usr/include/c++/5/bits/shared_ptr_base.h:522:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {tgui::ClickableWidget&}; _Tp = tgui::ClickableWidget; _Alloc = std::allocator<tgui::ClickableWidget>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr_base.h:617:4:   required from ‘std::__shared_count<_Lp>::__shared_count(std::_Sp_make_shared_tag, _Tp*, const _Alloc&, _Args&& ...) [with _Tp = tgui::ClickableWidget; _Alloc = std::allocator<tgui::ClickableWidget>; _Args = {tgui::ClickableWidget&}; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr_base.h:1097:35:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<tgui::ClickableWidget>; _Args = {tgui::ClickableWidget&}; _Tp = tgui::ClickableWidget; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr.h:319:64:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<tgui::ClickableWidget>; _Args = {tgui::ClickableWidget&}; _Tp = tgui::ClickableWidget]’
/usr/include/c++/5/bits/shared_ptr.h:614:39:   required from ‘std::shared_ptr<_Tp1> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = tgui::ClickableWidget; _Alloc = std::allocator<tgui::ClickableWidget>; _Args = {tgui::ClickableWidget&}]’
/usr/include/c++/5/bits/shared_ptr.h:629:39:   required from ‘std::shared_ptr<_Tp1> std::make_shared(_Args&& ...) [with _Tp = tgui::ClickableWidget; _Args = {tgui::ClickableWidget&}]’
/usr/local/include/TGUI/ClickableWidget.hpp:92:59:   required from here
/usr/include/c++/5/ext/new_allocator.h:120:4: error: invalid new-expression of abstract class type ‘tgui::ClickableWidget’
  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
    ^
In file included from /usr/local/include/TGUI/Label.hpp:30:0,
                 from main.cpp:1:
/usr/local/include/TGUI/ClickableWidget.hpp:55:20: note:   because the following virtual functions are pure within ‘tgui::ClickableWidget’:
     class TGUI_API ClickableWidget : public Widget
                    ^
In file included from /usr/local/include/TGUI/ClickableWidget.hpp:30:0,
                 from /usr/local/include/TGUI/Label.hpp:30,
                 from main.cpp:1:
/usr/local/include/TGUI/Widget.hpp:564:29: note: virtual tgui::Widget::Ptr tgui::Widget::clone() const
         virtual Widget::Ptr clone() const = 0;
                             ^
In file included from /usr/include/x86_64-linux-gnu/c++/5/bits/c++allocator.h:33:0,
                 from /usr/include/c++/5/bits/allocator.h:46,
                 from /usr/include/c++/5/string:41,
                 from /usr/local/include/TGUI/Exception.hpp:30,
                 from /usr/local/include/TGUI/Global.hpp:32,
                 from /usr/local/include/TGUI/Widget.hpp:30,
                 from /usr/local/include/TGUI/ClickableWidget.hpp:30,
                 from /usr/local/include/TGUI/Label.hpp:30,
                 from main.cpp:1:
/usr/include/c++/5/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = tgui::Label; _Args = {tgui::Label&}; _Tp = tgui::Label]’:
/usr/include/c++/5/bits/alloc_traits.h:256:4:   required from ‘static std::_Require<typename std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::type> std::allocator_traits<_Alloc>::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = tgui::Label; _Args = {tgui::Label&}; _Alloc = std::allocator<tgui::Label>; std::_Require<typename std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::type> = void]’
/usr/include/c++/5/bits/alloc_traits.h:402:16:   required from ‘static decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) std::allocator_traits<_Alloc>::construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = tgui::Label; _Args = {tgui::Label&}; _Alloc = std::allocator<tgui::Label>; decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) = <type error>]’
/usr/include/c++/5/bits/shared_ptr_base.h:522:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {tgui::Label&}; _Tp = tgui::Label; _Alloc = std::allocator<tgui::Label>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr_base.h:617:4:   required from ‘std::__shared_count<_Lp>::__shared_count(std::_Sp_make_shared_tag, _Tp*, const _Alloc&, _Args&& ...) [with _Tp = tgui::Label; _Alloc = std::allocator<tgui::Label>; _Args = {tgui::Label&}; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr_base.h:1097:35:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<tgui::Label>; _Args = {tgui::Label&}; _Tp = tgui::Label; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr.h:319:64:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<tgui::Label>; _Args = {tgui::Label&}; _Tp = tgui::Label]’
/usr/include/c++/5/bits/shared_ptr.h:614:39:   required from ‘std::shared_ptr<_Tp1> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = tgui::Label; _Alloc = std::allocator<tgui::Label>; _Args = {tgui::Label&}]’
/usr/include/c++/5/bits/shared_ptr.h:629:39:   required from ‘std::shared_ptr<_Tp1> std::make_shared(_Args&& ...) [with _Tp = tgui::Label; _Args = {tgui::Label&}]’
/usr/local/include/TGUI/Label.hpp:347:49:   required from here
/usr/include/c++/5/ext/new_allocator.h:120:4: error: invalid new-expression of abstract class type ‘tgui::Label’
  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
    ^
In file included from main.cpp:1:0:
/usr/local/include/TGUI/Label.hpp:47:20: note:   because the following virtual functions are pure within ‘tgui::Label’:
     class TGUI_API Label : public ClickableWidget, public WidgetBorders, public WidgetPadding
                    ^
In file included from /usr/local/include/TGUI/ClickableWidget.hpp:30:0,
                 from /usr/local/include/TGUI/Label.hpp:30,
                 from main.cpp:1:
/usr/local/include/TGUI/Widget.hpp:564:29: note: virtual tgui::Widget::Ptr tgui::Widget::clone() const
         virtual Widget::Ptr clone() const =  0;
                             ^


As though all methods from base class were not know in children classes, so making overriding tests fail.
The version of g++ is 5.2.1, and I'm on Ubuntu 15.10.

Any idea of why is that happening ?

texus

#1
Every time a change is pushed to github, TGUI is automatically compiled with 5 different compilers (2 on linux, 2 on windows, 1 on mac), so a compiler error is the last thing that I expect to see :)

Quote/usr/local/include/TGUI/ClickableWidget.hpp:90:29: error: ‘virtual tgui::Widget::Ptr tgui::ClickableWidget::clone()’ marked ‘override’, but does not override
         virtual Widget::Ptr clone() override
This error occurs because there is a "const" missing behind the function, but not only is there a "const" in the latest version, it is also located on line 96 and not line 90 like the error suggests.

I guess you had a different TGUI version installed before compiling the latest snapshot. I would delete all tgui folders that you have (especially /usr/local/include/TGUI/) and try installing the latest version again.

Edit: Just deleting the /usr/local/include/TGUI/ and re-running "sudo make install" should be enough. Looking closer at the errors I notice that you have some old files remaining which were not overwritten by the new version because the new version has these files in a different subfolder.

Dnake

#2
This worked, thank you  :)

Should I delete /usr/share/include/tgui/* every time I install a new version of TGUI ?
This will be done quite often, if this is needed at each API public change.
Maybe that should be a good idea to make a target in the Makefile that do it by itself ?

Edit: Oh, right, I understood why this is the first time I had to delete files. That's because you have moved files, not because of an API public change. I'll remember that for the next time :)

texus

You should never have to delete the folder.
Actually because you ask this question I looked at it again and I now realized why you were getting the error (because earlier I didn't understand why it happened). You are including TGUI/Label.hpp which is a file that no longer exists, it became TGUI/Widgets/Label.hpp. So it is just because you are including a file that doesn't really exist anymore. Since all TGUI examples just tell you to include TGUI/TGUI.hpp, including another file is at your own risk.

Dnake

Is the usual way to use SFML/TGUI to include the main header (TGUI.hpp or SFML/Graphics.hpp) ?
I thought that including only needed headers gave better compilation performance, without other loss.

texus

#5
Including the main header will always work because it contains everything you could possibly need.

Including only the headers that you need will indeed reduce the compile time, but there is no guarantee that this will work. Suppose I would forward declare the Theme class in the Widget.hpp header so that the theme class does not has to be included everywhere (which leads to faster compilation). Then trying to use the Theme class in your code will give errors because the declaration is missing. Every file that actually needs the Theme class would have to manually include Theme.hpp. So although only including the needed headers will lead to better compilation performance, you might need to include several "internal" headers manually as well for it to work. In TGUI this isn't such a big problem, but in other libraries if you are unlucky you have to include a lot of extra headers just to make the header work that you wanted.

Also when I change the file names or when I forward declare different classes you might have to change the includes in your files. When including the main header nothing would have changed in your code. So both have advantages and disadvantages.

Dnake

#6
Ok, thank you for your reply, I think I will include the main TGUI header.
I guess the documentation of the library have to indicate in one way or another which header to include to use the library. I don't think the best way to use Qt is to include <Qt/Qt.hpp> or something like this ^^
But I agree with you, for TGUI this is better in that way.

Edit: Now I know what means the sentence "This is an unstable release, API changes may break you code", there is alot of things that has changed recently in TGUI-0.7, some are easy to fix (replace all tgui::xx::create to std::make_shared<tgui::xx>) but others are more painful, like the old widget constructor with theme filename as parameters :)