Search code examples
c++mingwcross-compilingcodeblockswxwidgets

Code::Blocks/wxWidgets cross compile fails for Windows


I am trying to setup Code::Blocks in Linux to cross compile for Windows. I can switch between compilers OK but when I try to compile a (new empty) wxWidgets project. The Linux compiler succeeds and I can run the binary in Linux. The MingW compiler generates a lot of errors that I cannot explain. All the MingW tools listed in the toolchain setup are present. There are no messages for missing wx include files.
Can anyone explain what causes these messages?

The build log starts with these lines:

-------------- Build: Debug in wxTest (compiler: MingW GNU GCC cross compiler for Windows)---------------

i686-w64-mingw32-g++ -I/usr/lib/x86_64-linux-gnu/wx/include/gtk3-unicode-3.0 -I/usr/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread -Wall -g -I/usr/i686-w64-mingw32/lib/wx/include/i686-w64-mingw32-msw-unicode-static-3.0 -I/usr/i686-w64-mingw32/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -D__WXMSW__ -mthreads -I/usr/i686-w64-mingw32/include/ -c /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestApp.cpp -o obj/Debug/wxTestApp.o
i686-w64-mingw32-g++ -I/usr/lib/x86_64-linux-gnu/wx/include/gtk3-unicode-3.0 -I/usr/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread -Wall -g -I/usr/i686-w64-mingw32/lib/wx/include/i686-w64-mingw32-msw-unicode-static-3.0 -I/usr/i686-w64-mingw32/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -D__WXMSW__ -mthreads -I/usr/i686-w64-mingw32/include/ -c /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestMain.cpp -o obj/Debug/wxTestMain.o
i686-w64-mingw32-g++ -L/usr/i686-w64-mingw32/lib/ -o bin/Debug/wxTest obj/Debug/wxTestApp.o obj/Debug/wxTestMain.o  -L/usr/lib/x86_64-linux-gnu -pthread   -lwx_gtk3u_xrc-3.0 -lwx_gtk3u_html-3.0 -lwx_gtk3u_qa-3.0 -lwx_gtk3u_adv-3.0 -lwx_gtk3u_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0   
In file included from /usr/include/wx-3.0/wx/chkconf.h:1222,
                 from /usr/include/wx-3.0/wx/platform.h:596,
                 from /usr/include/wx-3.0/wx/defs.h:27,
                 from /usr/include/wx-3.0/wx/event.h:14,
                 from /usr/include/wx-3.0/wx/app.h:19,
                 from /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestApp.h:13,
                 from /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestApp.cpp:10:
/usr/i686-w64-mingw32/include/wx-3.0/wx/msw/chkconf.h:394:13: error: #error "wxUSE_DATAOBJ requires wxUSE_OLE"
  394 | #           error "wxUSE_DATAOBJ requires wxUSE_OLE"
      |             ^~~~~
/usr/i686-w64-mingw32/include/wx-3.0/wx/msw/chkconf.h:414:13: error: #error "wxMediaCtl requires wxActiveXContainer"
  414 | #           error "wxMediaCtl requires wxActiveXContainer"
      |             ^~~~~
In file included from /usr/include/wx-3.0/wx/platform.h:596,
                 from /usr/include/wx-3.0/wx/defs.h:27,
                 from /usr/include/wx-3.0/wx/event.h:14,
                 from /usr/include/wx-3.0/wx/app.h:19,
                 from /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestApp.h:13,
                 from /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestApp.cpp:10:
/usr/include/wx-3.0/wx/chkconf.h:1630:13: error: #error "wxRearrangeCtrl requires wxCheckListBox"
 1630 | #           error "wxRearrangeCtrl requires wxCheckListBox"
      |             ^~~~~
In file included from /usr/include/wx-3.0/wx/chkconf.h:1222,
                 from /usr/include/wx-3.0/wx/platform.h:596,
                 from /usr/include/wx-3.0/wx/defs.h:27,
                 from /usr/include/wx-3.0/wx/event.h:14,
                 from /usr/include/wx-3.0/wx/window.h:18,
                 from /usr/include/wx-3.0/wx/nonownedwnd.h:14,
                 from /usr/include/wx-3.0/wx/toplevel.h:20,
                 from /usr/include/wx-3.0/wx/frame.h:18,
                 from /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestMain.h:14,
                 from /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestMain.cpp:10:
/usr/i686-w64-mingw32/include/wx-3.0/wx/msw/chkconf.h:394:13: error: #error "wxUSE_DATAOBJ requires wxUSE_OLE"
  394 | #           error "wxUSE_DATAOBJ requires wxUSE_OLE"
      |             ^~~~~
/usr/i686-w64-mingw32/include/wx-3.0/wx/msw/chkconf.h:414:13: error: #error "wxMediaCtl requires wxActiveXContainer"
  414 | #           error "wxMediaCtl requires wxActiveXContainer"
      |             ^~~~~
In file included from /usr/include/wx-3.0/wx/platform.h:596,
                 from /usr/include/wx-3.0/wx/defs.h:27,
                 from /usr/include/wx-3.0/wx/event.h:14,
                 from /usr/include/wx-3.0/wx/window.h:18,
                 from /usr/include/wx-3.0/wx/nonownedwnd.h:14,
                 from /usr/include/wx-3.0/wx/toplevel.h:20,
                 from /usr/include/wx-3.0/wx/frame.h:18,
                 from /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestMain.h:14,
                 from /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestMain.cpp:10:
/usr/include/wx-3.0/wx/chkconf.h:1630:13: error: #error "wxRearrangeCtrl requires wxCheckListBox"
 1630 | #           error "wxRearrangeCtrl requires wxCheckListBox"
      |             ^~~~~
In file included from /usr/include/wx-3.0/wx/memory.h:15,
                 from /usr/include/wx-3.0/wx/object.h:19,
                 from /usr/include/wx-3.0/wx/event.h:16,
                 from /usr/include/wx-3.0/wx/window.h:18,
                 from /usr/include/wx-3.0/wx/nonownedwnd.h:14,
                 from /usr/include/wx-3.0/wx/toplevel.h:20,
                 from /usr/include/wx-3.0/wx/frame.h:18,
                 from /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestMain.h:14,
                 from /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestMain.cpp:10:
/usr/include/wx-3.0/wx/string.h:211:15: error: ‘wxUniChar wxCStrData::operator[](unsigned int) const’ cannot be overloaded with ‘wxUniChar wxCStrData::operator[](size_t) const’
  211 |     wxUniChar operator[](unsigned int n) const { return operator[](size_t(n)); }
      |               ^~~~~~~~
/usr/include/wx-3.0/wx/string.h:207:22: note: previous declaration ‘wxUniChar wxCStrData::operator[](size_t) const’
  207 |     inline wxUniChar operator[](size_t n) const;
      |                      ^~~~~~~~
/usr/include/wx-3.0/wx/string.h:1551:15: error: ‘wxUniChar wxString::operator[](unsigned int) const’ cannot be overloaded with ‘wxUniChar wxString::operator[](size_t) const’
 1551 |     wxUniChar operator[](unsigned int n) const
      |               ^~~~~~~~
/usr/include/wx-3.0/wx/string.h:1548:15: note: previous declaration ‘wxUniChar wxString::operator[](size_t) const’
 1548 |     wxUniChar operator[](size_t n) const

In case this is relevant, I compiled wxWidgets with these lines:

./configure prefix=/usr/i686-w64-mingw32 --host=i686-w64-mingw32 --enable-unicode --build=`./config.guess` --disable-shared

make

make install

./configure exits with: Configured wxWidgets 3.0.5 for `i686-w64-mingw32'

but before I run make, config.log contains these errors

$ cat config.log|grep -i "error:"
i686-w64-mingw32-gcc: error: unrecognized command line option '-V'
i686-w64-mingw32-gcc: fatal error: no input files
i686-w64-mingw32-gcc: error: unrecognized command line option '-qversion'; did you mean '--version'?
i686-w64-mingw32-gcc: fatal error: no input files
conftest.c:15:17: error: unknown type name 'choke'
conftest.c:9:10: fatal error: ac_nonexistent.h: No such file or directory
conftest.c:9:10: fatal error: ac_nonexistent.h: No such file or directory
conftest.c:9:10: fatal error: sgtty.h: No such file or directory
conftest.c:9:10: fatal error: termio.h: No such file or directory
i686-w64-mingw32-g++: error: unrecognized command line option '-V'
i686-w64-mingw32-g++: fatal error: no input files
i686-w64-mingw32-g++: error: unrecognized command line option '-qversion'; did you mean '--version'?
i686-w64-mingw32-g++: fatal error: no input files
conftest.cpp:15:17: error: 'choke' was not declared in this scope
conftest.cpp:15:17: error: 'choke' was not declared in this scope
conftest.c:57:10: fatal error: langinfo.h: No such file or directory
conftest.c:60:12: error: size of array 'test_array' is negative

Solution

  • I've tried different compiling options for the widgets but that did not cause the above problems. Today I noticed that the execution bit of the file permission for wx-config was missing:

    /usr/i686-w64-mingw32/bin/wx-config: Permission denied
    

    Now that I've changed that, I get a lot of different messages in the build log:

    i686-w64-mingw32-g++ -Wall -I/usr/i686-w64-mingw32/lib/wx/include/i686-w64-mingw32-msw-unicode-static-3.0 -I/usr/i686-w64-mingw32/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -D__WXMSW__ -mthreads -g -I/usr/i686-w64-mingw32/lib/wx/include/i686-w64-mingw32-msw-unicode-static-3.0 -I/usr/i686-w64-mingw32/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -D__WXMSW__ -mthreads -I/usr/i686-w64-mingw32/include/ -c /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestApp.cpp -o obj/Debug/wxTestApp.o
    i686-w64-mingw32-g++ -Wall -I/usr/i686-w64-mingw32/lib/wx/include/i686-w64-mingw32-msw-unicode-static-3.0 -I/usr/i686-w64-mingw32/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -D__WXMSW__ -mthreads -g -I/usr/i686-w64-mingw32/lib/wx/include/i686-w64-mingw32-msw-unicode-static-3.0 -I/usr/i686-w64-mingw32/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -D__WXMSW__ -mthreads -I/usr/i686-w64-mingw32/include/ -c /home/data/VBOX/VBOX_DATA/CodeBlocks/wxTest/wxTestMain.cpp -o obj/Debug/wxTestMain.o
    i686-w64-mingw32-g++ -L/usr/i686-w64-mingw32/lib/ -o bin/Debug/wxTest obj/Debug/wxTestApp.o obj/Debug/wxTestMain.o  -L/usr/lib/x86_64-linux-gnu -pthread   -lwx_gtk3u_xrc-3.0 -lwx_gtk3u_html-3.0 -lwx_gtk3u_qa-3.0 -lwx_gtk3u_adv-3.0 -lwx_gtk3u_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0   
    /usr/bin/i686-w64-mingw32-ld: cannot find -lwx_gtk3u_xrc-3.0
    /usr/bin/i686-w64-mingw32-ld: cannot find -lwx_gtk3u_html-3.0
    /usr/bin/i686-w64-mingw32-ld: cannot find -lwx_gtk3u_qa-3.0
    /usr/bin/i686-w64-mingw32-ld: cannot find -lwx_gtk3u_adv-3.0
    /usr/bin/i686-w64-mingw32-ld: cannot find -lwx_gtk3u_core-3.0
    /usr/bin/i686-w64-mingw32-ld: cannot find -lwx_baseu_xml-3.0
    /usr/bin/i686-w64-mingw32-ld: cannot find -lwx_baseu_net-3.0
    /usr/bin/i686-w64-mingw32-ld: cannot find -lwx_baseu-3.0
    collect2: error: ld returned 1 exit status
    Process terminated with status 1 (0 minute(s), 1 second(s))
    9 error(s), 0 warning(s) (0 minute(s), 1 second(s))
    

    I also solved that last bit, the compiler tried to link linux libraries. After I changed in the "Global compiler settings" -> "linker settings" -> "Other linker options" -> "`wx-config --libs`" to: "`/usr/i686-w64-mingw32/bin/wx-config --libs`" those messages were gone. Also "Compiler settings" -> "`/usr/i686-w64-mingw32/bin/wx-config --cflags`" needs a full path to the Windows version of wx-config.

    The last time I configured wxWidgets:

    ./configure --prefix=/usr/i686-w64-mingw32 --host=i686-w64-mingw32 --enable-unicode --build=`./config.guess` --disable-shared --with-msw
    

    Now my project cross compiles for Windows