new wx3.1.1 src compile error

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

new wx3.1.1 src compile error

Post by cutecode »

I tried it on Linux Debian and Linux AstraLinux

1. I downloaded the newest wx version with this comand

Code: Select all

git clone --recurse-submodules https://github.com/wxWidgets/wxWidgets.git
2. builded wx with this comand

Code: Select all

../configure --enable-debug --enable-shared --enable-unicode --with-gtk=3
3. builded the minimal sample - it runs without errors
4. added to minimal.cpp this line of code, just before class MyApp declaation

Code: Select all

struct strucSh
{
	bool m_bSh;
};

WX_DECLARE_OBJARRAY(strucSh*, ar);
5. run make and I get plenty lines of errors

Code: Select all

alexander@debian:~/Documents/wx/_debug/samples/minimal$ make
/home/alexander/Documents/wx/_debug/bk-deps g++ -c -o minimal_minimal.o -D__WXGTK__      -I../../../samples/minimal -DWXUSINGDLL -I../../../samples/minimal/../../samples -Wall -Wundef -Wunused-parameter -Wno-ctor-dtor-privacy -Woverloaded-virtual -Wno-deprecated-declarations  -D_FILE_OFFSET_BITS=64 -I/home/alexander/Documents/wx/_debug/lib/wx/include/gtk3-unicode-3.1 -I../../../include -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -pthread -g -O0 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/freetype2 -pthread -I/usr/include/gtk-3.0/unix-print -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -fvisibility=hidden -fvisibility-inlines-hidden ../../../samples/minimal/minimal.cpp
In file included from ../../../include/wx/wx.h:16:0,
                 from ../../../samples/minimal/minimal.cpp:29:
../../../samples/minimal/minimal.cpp:49:28: error: expected ‘)’ before ‘*’ token
 WX_DECLARE_OBJARRAY(strucSh*, ar);
                            ^
../../../include/wx/dynarray.h:660:43: note: in definition of macro ‘WX_DECLARE_OBJARRAY_WITH_DECL’
     typedef int (wxCMPFUNC_CONV *CMPFUNC##T)(T **pItem1, T **pItem2);         \
                                           ^
../../../include/wx/dynarray.h:646:5: note: in expansion of macro ‘WX_DECLARE_USER_EXPORTED_OBJARRAY’
     WX_DECLARE_USER_EXPORTED_OBJARRAY(T, name, wxARRAY_DEFAULT_EXPORT)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../samples/minimal/minimal.cpp:49:1: note: in expansion of macro ‘WX_DECLARE_OBJARRAY’
 WX_DECLARE_OBJARRAY(strucSh*, ar);
 ^
../../../include/wx/dynarray.h: In instantiation of ‘void wxBaseObjectArray<T, Traits>::Add(const T&, size_t) [with T = strucSh*; Traits = wxObjectArrayTraitsForar; size_t = long unsigned int]’:
../../../include/wx/dynarray.h:441:16:   required from ‘void wxBaseObjectArray<T, Traits>::DoCopy(const wxBaseObjectArray<T, Traits>&) [with T = strucSh*; Traits = wxObjectArrayTraitsForar]’
../../../include/wx/dynarray.h:298:15:   required from ‘wxBaseObjectArray<T, Traits>::wxBaseObjectArray(const wxBaseObjectArray<T, Traits>&) [with T = strucSh*; Traits = wxObjectArrayTraitsForar]’
../../../samples/minimal/minimal.cpp:49:1:   required from here
../../../include/wx/dynarray.h:371:39: error: invalid initialization of non-const reference of type ‘const strucSh*&’ from an rvalue of type ‘const strucSh*’
         T* const pItem = Traits::Clone(item);
                          ~~~~~~~~~~~~~^~~~~~
../../../include/wx/dynarray.h:655:19: note:   initializing argument 1 of ‘static strucSh** wxObjectArrayTraitsForar::Clone(const strucSh*&)’
         static T* Clone(const T& item);                                       \
                   ^
../../../include/wx/dynarray.h:669:5: note: in expansion of macro ‘WX_DECLARE_OBJARRAY_WITH_DECL’
     WX_DECLARE_OBJARRAY_WITH_DECL(T, name, class expmode)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../include/wx/dynarray.h:646:5: note: in expansion of macro ‘WX_DECLARE_USER_EXPORTED_OBJARRAY’
     WX_DECLARE_USER_EXPORTED_OBJARRAY(T, name, wxARRAY_DEFAULT_EXPORT)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../samples/minimal/minimal.cpp:49:1: note: in expansion of macro ‘WX_DECLARE_OBJARRAY’
 WX_DECLARE_OBJARRAY(strucSh*, ar);
 ^
../../../include/wx/dynarray.h:378:59: error: invalid initialization of non-const reference of type ‘const strucSh*&’ from an rvalue of type ‘const strucSh*’
             base::operator[](nOldSize + i) = Traits::Clone(item);
                                              ~~~~~~~~~~~~~^~~~~~
../../../include/wx/dynarray.h:655:19: note:   initializing argument 1 of ‘static strucSh** wxObjectArrayTraitsForar::Clone(const strucSh*&)’
         static T* Clone(const T& item);                                       \
                   ^
../../../include/wx/dynarray.h:669:5: note: in expansion of macro ‘WX_DECLARE_OBJARRAY_WITH_DECL’
     WX_DECLARE_OBJARRAY_WITH_DECL(T, name, class expmode)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../include/wx/dynarray.h:646:5: note: in expansion of macro ‘WX_DECLARE_USER_EXPORTED_OBJARRAY’
     WX_DECLARE_USER_EXPORTED_OBJARRAY(T, name, wxARRAY_DEFAULT_EXPORT)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../samples/minimal/minimal.cpp:49:1: note: in expansion of macro ‘WX_DECLARE_OBJARRAY’
 WX_DECLARE_OBJARRAY(strucSh*, ar);
 ^
Makefile:178: ошибка выполнения рецепта для цели «minimal_minimal.o»
make: *** [minimal_minimal.o] Ошибка 1
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

Re: new wx3.1.1 src compile error

Post by cutecode »

Hm, after rereading docs I found that one should remove "*" sign

Code: Select all

WX_DECLARE_OBJARRAY(MyClass, wxArrayOfMyClass); // note: not "MyClass *"!]
I rewrote the code like that and it compiled without errors

Code: Select all

struct strucSh
{
	bool m_bSh;
};

WX_DECLARE_OBJARRAY(strucSh, ar);
TY
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

Re: new wx3.1.1 src compile error

Post by cutecode »

Hm, in fact I need to save pointers to object, not save them by value. Is it possible?
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: new wx3.1.1 src compile error

Post by doublemax »

Try:

Code: Select all

WX_DEFINE_ARRAY(strucSh*, ar);
Or, even better: Don't use these legacy macros at all. Use an STL container.
Use the source, Luke!
Post Reply