简体   繁体   English

从Linux到Windows交叉编译wxWidgets代码

[英]Cross-Compiling wxWidgets code from Linux to Windows

I use Code::Blocks IDE with wxWidgets in Debian 8.9 Jessie (x86-64). 我在Debian 8.9 Jessie(x86-64)中使用带有wxWidgets的Code :: Blocks IDE。
When I use the GNU GCC Compiler everything works fine thus compiling nice wxWidgets executable for Linux. 当我使用GNU GCC编译器时,一切正常,因此为Linux编译了不错的wxWidgets可执行文件。
But I need to have my program working on Windows platforms so I have to do cross-compiling. 但是我需要让我的程序在Windows平台上运行,所以我必须进行交叉编译。
I have installed mingw32 and followed the cross-compiling instructions given here . 我已经安装了mingw32并遵循此处给出的交叉编译说明。
I did my wxWidgets build configuration as follows: 我做了wxWidgets构建配置,如下所示:

./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. 之所以如此,是因为我拥有的MinGW编译器是i686-w64-mingw32 ,位于文件夹/usr/i686-w64-mingw32 ,而wxWidgets版本是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. 我在Code :: Blocks中设置的编译器应该正确,因为我设法对简单的控制台应用程序进行了交叉编译,并且这些程序可以在Windows 10.0上正常运行。 But when it comes to wxWidgets applications there are several problems: 但是当涉及到wxWidgets应用程序时,存在几个问题:

  1. The compiler gives me the error (it happens when --static is added to Other compiler options in the build options for the project): 编译器给我错误(将--static添加到项目的构建选项中的“ Other compiler options中时发生):

     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). 现在,由于有问题的wx目录位于路径/usr/i686-w64-mingw32/include/wx-3.1我将此路径添加到了项目的搜索目录中(目前仅是构建目标)。 This worked fine to proceed further. 这样做可以继续进行。
    My compiler settings are: wx-config --host=i686-w64-mingw32 --static --cflags 我的编译器设置为: 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. 好的,我已经在/usr/i686-w64-mingw32/lib/wx/include/i686-w64-mingw32-msw-unicode-static-3.1找到了这个/usr/i686-w64-mingw32/lib/wx/include/i686-w64-mingw32-msw-unicode-static-3.1 ,因此将该路径添加到了编译器搜索目录中。

  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 我的链接器设置为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. 我尝试使用wxWidgets库的几个不同的构建选项来解决此问题,但对结果没有影响。 So please, someone help! 所以请有人帮忙!

I also noticed that running ./config.guess form the wxWidgets download directory gives me x86_64-unknown-linux-gnu . 我还注意到,从wxWidgets下载目录运行./config.guess会给我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 ? 因此,这意味着我应该使用x86_64-w64-mingw32 (我已在/usr/x86_64-w64-mingw32安装了此程序)编译器,而不是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 . 因此,主要问题是在Other compiler options无法识别命令wx-config --static --cflagsOther linker options无法识别wx-config --static --libs

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" . 即使我从主目录在.bashrc文件中的wx-config文件中添加了路径,问题仍然存在,即export PATH="$PATH:/usr/i686-w64-mingw32/bin" At that time I was able to run wx-config from the terminal at any location. 那时,我能够从任何位置的终端运行wx-config。

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 . 为了解决这个问题,我将Other compiler options的选项更改为/usr/i686-w64-mingw32/bin/wx-config --static --cflags/usr/i686-w64-mingw32/bin/wx-config --static --libs /usr/i686-w64-mingw32/bin/wx-config --static --cflags /usr/i686-w64-mingw32/bin/wx-config --static --libsOther 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. 我在Link libraries添加了libstdc++-6.dll的位置(在文件管理器中通过搜索即可找到它),并在Other linker options-static-static-libgcc标志,最后使用最小的示例进行了测试正如伊戈尔建议的那样。 Just create new console application, add minimal.cpp file to it and all of the mentioned above. 只需创建新的控制台应用程序,向其中以及上面提到的所有内容添加minimal.cpp文件即可。

The compiler did a Minimal.exe file that I have opened successfully with wine. 编译器做了一个Minimal.exe文件,我已经用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. 注意:我在问题中提到的所有包含目录都在wx-config --cflags用于编译器)和wx-config --libs用于链接器)中,因此无需在搜索目录中添加它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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