简体   繁体   中英

Cross-Compiling wxWidgets code from Linux to Windows

I use Code::Blocks IDE with wxWidgets in Debian 8.9 Jessie (x86-64).
When I use the GNU GCC Compiler everything works fine thus compiling nice wxWidgets executable for Linux.
But I need to have my program working on Windows platforms so I have to do cross-compiling.
I have installed mingw32 and followed the cross-compiling instructions given here .
I did my wxWidgets build configuration as follows:

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

This is so because the MinGW compiler I have is i686-w64-mingw32 , located in the folder /usr/i686-w64-mingw32 , and wxWidgets version is 3.1. My compiler set-up in Code::Blocks should be correct because I managed to do cross-compiling for simple console applications and those run properly on Windows 10.0. But when it comes to wxWidgets applications there are several problems:

  1. The compiler gives me the error (it happens when --static is added to Other compiler options in the build options for the project):

     fatal error: wx/app.h: No such file or directory| 

    Now since wx directory in question is in the path /usr/i686-w64-mingw32/include/wx-3.1 I added this path to the search directories for the project (the build target only for the moment). This worked fine to proceed further.
    My compiler settings are: wx-config --host=i686-w64-mingw32 --static --cflags

  2. The compiler swears again (not surprised though :-)):

     fatal error: wx/setup.h: No such file or directory| 

    Ok I've found this one in /usr/i686-w64-mingw32/lib/wx/include/i686-w64-mingw32-msw-unicode-static-3.1 , so added this path to the compiler search directories.

  3. The linker is swearing this time (creeping on my nerves):

    for the build target:

     undefined reference to `wxEntry(HINSTANCE__*, HINSTANCE__*, char*, int)'| 

    for the release target:

     undefined reference to `wxAppConsoleBase::CheckBuildOptions(char const*, char const*)'| 

    My linker settings are wx-config --host=i686-w64-mingw32 --static --libs

I tried hard to fix this with several different build options for the wxWidgets library but with no effect on the result. So please, someone help!

I also noticed that running ./config.guess form the wxWidgets download directory gives me x86_64-unknown-linux-gnu . Thus this mean I should use x86_64-w64-mingw32 (I have this one installed in /usr/x86_64-w64-mingw32 ) compiler instead i686-w64-mingw32 ?

So the main issue is that the command wx-config --static --cflags is not recognized in Other compiler options and wx-config --static --libs is not recognized in Other linker options .

The problem persisted even though I added the path to wx-config file in the .bashrc file from the home directory, ie export PATH="$PATH:/usr/i686-w64-mingw32/bin" . At that time I was able to run wx-config from the terminal at any location.

To solve it I've changed the options to /usr/i686-w64-mingw32/bin/wx-config --static --cflags in Other compiler options and /usr/i686-w64-mingw32/bin/wx-config --static --libs in Other linker options . This worked as a charm.

I've added the location of libstdc++-6.dll (simply found it with a search in the file manager) in Link libraries and the flags -static and -static-libgcc in Other linker options and finally did the testing with the minimal sample as Igor suggested. Just create new console application, add minimal.cpp file to it and all of the mentioned above.

The compiler did a Minimal.exe file that I have opened successfully with wine.

Note: All the include directories I mentioned in my question were in wx-config --cflags for the compiler and wx-config --libs for the linker, so no need to add them in search directories.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM