Author Topic: Howto - Cross Compiling in Linux using MingW32  (Read 623149 times)

Offline Ganbito

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #30 on: August 09, 2008, 08:59:11 pm »
I want to cross compile my wxwidgets application but there is nothing in this (good howto) about it, so I wanted to add that to this howto (and update it too).

By the way, I follow the howto but when I tried to debug the sample aplication (on the last step) I have the following output on the Debbuger window:

Code
Building to ensure sources are up-to-date
Build succeeded
Selecting target:
Debug
Adding source dir: /home/cesar/CodeBlocks/probaMinGW32/
Adding source dir: /home/cesar/CodeBlocks/probaMinGW32/
Adding file: bin/Debug_L64/probaMinGW32.exe
Starting debugger:
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb 6.3
Error creating process Z:\home\cesar\CodeBlocks\probaMinGW32/bin/Debug_L64/probaMinGW32.exe, (error 32)

And, obviously, if I try to continue debuging (Next Instruction, Step into...) I obtain an error:
Code
Continuing...
The program is not being run.
Debugger finished with status 1

Really, I do not want to debug Windows applications under linux, just compile them, but I do not want to post a buggy howto, or leave this buggy (actually) now that I find it for the users who will need it in the near future. So, if someone can help me, it would be appreciated.

I am using:
-Ubuntu 8.04 x86_64
-Code::Blocks svn5177
-MinGW32 4.2.1
-Insight 6.3
-Wine 1.0

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #31 on: August 09, 2008, 09:41:09 pm »
Have you read my wiki-article: http://wiki.codeblocks.org/index.php?title=Cross_Compiling_wxWidgets_Applications_on_Linux ?

There you can also find some thoughts about debugging windows-applications from within C::B compiled for linux.

Offline Ganbito

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #32 on: August 10, 2008, 12:27:17 pm »
Well, I have followed all the links I found about it (in this forum, in codeblocks wiki and in wxWidgets wiki) but I miss yours. :oops:

So I go and try it just now. Also I found some problems with the wxWidgets for MSW (with the repository of http://apt.wxwidgets.org/ and build from source), so let's try you wiki!!! :)

P.D.: And my nightly comes from your repository, so thank you for all. :wink:

Offline Ganbito

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #33 on: August 10, 2008, 01:30:04 pm »
Well, when I added the wxWidgets repository I use it as "gutsy-wx" instead "hardy-wx" because at that time wxWidgets have not an hardy repository, so I try to update it before trying your wiki-article and now it works.

I follow your article and now I can cross compile correctly wxWidgets applications. I have solved one modifying <wx/chkconf.h> which is best solved using
Code
--prefix=/usr/i586-mingw32msvc
as you do. The other error (wxUSE_DATAOBJ not defined) have been solved by any of the steps, but I don't what. The fact is that it works, so THANKS.

When I tried the debugger (insight) it reported the same errors, so I download the recent gdb as your wiki says (6.8-rc) and now the debugger don't crash, but it report some errors (with the sample console application as suggested by this topic howto):
Code
Error while mapping shared library sections:
Error while reading shared library symbols:
Error while mapping shared library sections:
Error while reading shared library symbols:
Error while reading shared library symbols:
Error while reading shared library symbols:
Error while reading shared library symbols:
Error while mapping shared library sections:
Error while reading shared library symbols:
Error while reading shared library symbols:
Error while reading shared library symbols:

With only this little inconvenient, I can say that this howto is well superceded by your wiki-article. Thank you ;)

Offline Ganbito

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #34 on: August 10, 2008, 02:11:24 pm »
Eps, too early it seems to be finished.

I have confused the build target, the cross compiler one don't work. I'm confused about a section of your article: "Fixing build options".
Code
In the Build options of the project you have to move `wx-config --cflags` from the global Compiler settings -> Other options to the one for the standard build targets (Debug and Release).

`wx-config --cflags`??? I didn't have that.

Code
The appropriate calls to wx-config for the WinRelease must have the parameter: --host=i586-mingw32msvc included and should have the parameter --static set also.

If I understand you, I have to go to the Build options of WinRelease-target and then to Compiler settings -> Other options and add:
Code
`wx-config --host=i586-mingw32msvc --static --prefix=/usr/i586-mingw32msvc`

If I do that I get this Build Messages:
Code
/usr/include/wx-2.8/wx/platform.h|540|error: wx/msw/libraries.h: No such file or directory|
/usr/include/wx-2.8/wx/defs.h|2820|error: conflicting declaration ‘typedef struct GtkWidget* WXWidget’|
/usr/include/wx-2.8/wx/defs.h|2611|error: ‘WXWidget’ has a previous declaration as ‘typedef void* WXWidget’|
/usr/include/wx-2.8/wx/string.h|827|error: ‘wxChar& wxString::operator[](unsigned int)’ cannot be overloaded|
/usr/include/wx-2.8/wx/string.h|824|error: with ‘wxChar& wxString::operator[](size_t)’|
/usr/include/wx-2.8/wx/hashmap.h||In member function ‘wxLongToLongHashMap_wxImplementation_HashTable::Node** wxLongToLongHashMap_wxImplementation_HashTable::GetNodePtr(const long int&) const’:|
/usr/include/wx-2.8/wx/hashmap.h|714|warning: dereferencing type-punned pointer will break strict-aliasing rules|
/usr/include/wx-2.8/wx/clntdata.h||In member function ‘wxShadowObjectMethods_wxImplementation_HashTable::Node** wxShadowObjectMethods_wxImplementation_HashTable::GetNodePtr(const wxString&) const’:|
/usr/include/wx-2.8/wx/clntdata.h|20|warning: dereferencing type-punned pointer will break strict-aliasing rules|
/usr/include/wx-2.8/wx/clntdata.h||In member function ‘wxShadowObjectFields_wxImplementation_HashTable::Node** wxShadowObjectFields_wxImplementation_HashTable::GetNodePtr(const wxString&) const’:|
/usr/include/wx-2.8/wx/clntdata.h|25|warning: dereferencing type-punned pointer will break strict-aliasing rules|
/usr/include/wx-2.8/wx/gdicmn.h||In member function ‘wxStringToColourHashMap_wxImplementation_HashTable::Node** wxStringToColourHashMap_wxImplementation_HashTable::GetNodePtr(const wxString&) const’:|
/usr/include/wx-2.8/wx/gdicmn.h|544|warning: dereferencing type-punned pointer will break strict-aliasing rules|
/usr/include/wx-2.8/wx/filefn.h|398|error: zero width for bit-field ‘wxAssert_399::BadFileSizeType’|
/usr/include/wx-2.8/wx/image.h||In member function ‘wxImageHistogramBase_wxImplementation_HashTable::Node** wxImageHistogramBase_wxImplementation_HashTable::GetNodePtr(const long unsigned int&) const’:|
/usr/include/wx-2.8/wx/image.h|136|warning: dereferencing type-punned pointer will break strict-aliasing rules|
||=== Build finished: 6 errors, 5 warnings ===|

Firstly, I understand you that I have to put to Compiler settings -> Other options:
Code
--host=i586-mingw32msvc --static --prefix=/usr/i586-mingw32msvc
but I obtain in the Build log:
Code
Compiling: probaWxMinGWApp.cpp
i586-mingw32msvc-g++: unrecognized option '-pthread'
cc1plus: error: unrecognized command line option "-fhost=i586-mingw32msvc"
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
so I try the other option.

What I am doing wrong?

This afternoon I will try to compile wxWidgets myself (one more time) if it fixes something.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #35 on: August 10, 2008, 02:36:23 pm »
All the "wx-config"-stuff is only needed if you cross-compile with wxWidgets, it's not needed for pure console or win32-apps. If you want to use the latter, just copy a wizard-created win32-gui project from a win-box to your linux-box (you might have to fix something in properties or build options, Im not sure about that at the moment).

If you do so just start with the wxwidgets-wizard as I do in my example in the wiki.

And you need the cross-build-libs for wxWidgets, that I provide on my server. You can of course try to compile them yourself, but mine should work out of the box, if you have wxWidgets-2.8.8 installed.

You might need to install the "wx2.8-headers-msw-force-depends", if you get errors, because the "wx2.8-headers"-version from your distro, or from wxwidgets.org does not match the exact version of my "wx2.8-headers-msw".
« Last Edit: August 10, 2008, 02:39:35 pm by jens »

Offline Ganbito

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #36 on: August 10, 2008, 03:52:46 pm »
I'm using wxWidgets on my application, so I need to cross compile with it.

I've created a new wxWidgets project with the wizard as you do in the wiki.

I've picked "libwxmws2.8dbg", "libwxmsw2.8dev", "wx2.8headers-msw" and "wx2.8-headers-msw-force-depends" from your repository.

I just take a look on synaptic and your wxMSW is 2.8.8.0 and my wxWidgets is 2.8.8.1 (from wxWidgets repository) so this can be the problem, as you write.

Then I try to compile wxWidgets myself with the ./configure of your wiki and obtain this:
Code
Configured wxWidgets 2.8.8 for `i586-pc-mingw32msvc'

  Which GUI toolkit should wxWidgets use?                 msw
  Should wxWidgets be compiled into single library?       no
  Should wxWidgets be compiled in debug mode?             no
  Should wxWidgets be linked as a shared library?         no
  Should wxWidgets be compiled in Unicode mode?           yes
  What level of wxWidgets compatibility should be enabled?
                                       wxWidgets 2.4      no
                                       wxWidgets 2.6      yes
  Which libraries should wxWidgets use?
                                       jpeg               builtin
                                       png                builtin
                                       regex              builtin
                                       tiff               builtin
                                       zlib               builtin
                                       odbc               no
                                       expat              builtin
                                       libmspack          no
                                       sdl                no

Why mine should not compile as a single library?

Well, I go to try it.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #37 on: August 10, 2008, 05:53:39 pm »
Why mine should not compile as a single library?

I also do not use monolithic libs for my .deb's.

It was just an example-output in the wiki, but I just corrected it to show the output you get with the "./configure"-line I used as example to avoid misunderstandings.

The changes between 2.8.8.0 and 2.8.8.1 do not touch msw-builds afaik. But I will update my repo anyway to keep the version-numbering consistent.
EDIT (2.):
wxwidgets.org does not provide sources for 2.8.8.1 with msw build-tree included, that means I would have to merge  it manually, but that's a little too much work, if it's only done to keep the version-number in sync.


EDIT:
Btw: the cross-libs only depend on the "wx2.8-headers"-package, so a change to source-code for linux (except for the headerfiles perhaps) can not harm the msw-cross-libraries.
« Last Edit: August 11, 2008, 08:38:31 am by jens »

Offline Ganbito

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #38 on: August 12, 2008, 02:19:29 am »
I agree with you that it is a little too much work. However, as I am going to need it, I give it another chance.

I started using wxWidgets 2.8.8.1 from wxWidgets repo and wxMSW 2.8.8.0 from your repo, I've configured Code::Blocks as your wiki-article says, using `wx-config --prefix=/usr/i586-mingw32msvc --host=i586-mingw32msvc --static` in Compiler settings -> Other options of the Windows build target.

I found lots of errors, mostly in wx header files, saying that it can find include file /usr/include/wx-2.8/wx/msw/include-file.h and I thinked about fix all manually, but I was lazy so I finally compile wxMSW with the following options:
Code
./configure --host=i586-mingw32msvc --enable-unicode --build=`./config.guess` --disable-shared

That is, yours without --prefix (it installs to /usr/local) and it get to work, only a few warnings, but it compiles and runs in Windows XP. I also add the flags to compiling and linking options for the MinGW32 compiler as suggested by http://wiki.wxwidgets.org/Cross-Compiling_Under_Linux but it seems that they are not necessary.

Then, I try cross compiling my own project and I get problems with wxPropertyGrid (the same which Code::Blocks use) for the cross build, but that is already another story.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #39 on: August 12, 2008, 06:20:57 am »
Did you run "wx-config --list" before compiling everything new.
Are you sure everything was setup correctly and that there are not rests of former tries to compile wxWidgets on your own ?

About wxPropertyGrid:

wxPropertyGRid is not part of wxWidgets.
It's a standalone-project ( http://wxpropgrid.sourceforge.net/cgi-bin/index ).

I don't know how to set it up for cross-compiling.
Sorry.
« Last Edit: August 12, 2008, 06:23:38 am by jens »

Offline Ganbito

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #40 on: August 15, 2008, 05:59:14 pm »
I've reinstalled Ubuntu (for the garbage generated with manual compiling wxWidgets) and decided to give a last chance to your wxMSW.

This time I see that I have set `wx-config --prefix=/usr/i586-mingw32msvc --host=i586-mingw32msvc --static` in Compiler settings -> Other options but don't in Linker Settings -> Other options. But there is no change, it continues to search include files in /usr/include/wx-2.8/wx/msw/ so it can't compile.

Then I compile wxWidgets with the same configure options as I write in the last post and it get to work right (after uninstall your wxMSW).

I know that wxPropertyGrid is not part of wxWidgets. I wrote:
Then, I try cross compiling my own project and I get problems with wxPropertyGrid (the same which Code::Blocks use) for the cross build, but that is already another story.
only as a comment. This time I've could cross compile it with my windows release.

After that (I don't know if it is related with cross-compilation, but I get this error after setting Code-Blocks and my project for cross-compiling) I get this error building with the default Debug-target (wich I don't modify at any time):

Code
cc1plus: error: no se reconoce la opción de línea de comando "-mthreads"
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings

Approximate translation:

Code
cc1plus: error: unknown command line option "-mthreads"
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings

This only happens when I try to build the whole project (or Rebuild), not when building changes.

Any idea?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #41 on: August 15, 2008, 07:19:19 pm »
If you did not set -mthreads manually, it means that you use the "wx-config" of the cross-libs for the linux-build ("-mthreads" belongs to win, "-pthread" to linux).

Can you provide a sample project where the error occurs ?
If possible it would be nice if you can also send me your default.conf ("~/.codeblocks/default.conf").

Offline Ganbito

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #42 on: August 16, 2008, 12:35:45 am »
You are right.

After compiling (and installing) wxMSW, I've check the wx-config --list output and it was right.

But now, I recheck it and only obtain:

Code
   Default config is i586-mingw32msvc-msw-unicode-release-static-2.8

Default config will be used for output

I don't know when it changed, but it changed.

I'm trying to solve it by making a symbolic link to the right wx-config:
Code
$ sudo ln -s /usr/lib/wx/config/gtk2-unicode-release-2.8 /usr/bin/wx-config
but I obtain the same as above with wx-config --list.

In contrast, if I try /usr/lib/wx/config/gtk2-unicode-release-2.8 --list I obtain:
Code

    Default config is gtk2-unicode-release-2.8

  Default config will be used for output

  Alternate matches:
    base-unicode-debug-2.8
    base-unicode-release-2.8
    gtk2-unicode-debug-2.8

  Also available in /usr:
    i586-mingw32msvc-msw-unicode-release-static-2.8


Even if I copy it directly, I obtain the same result, I'm confused.

I will continue with it tomorrow. I think that is time to go to wxWidgets forum.

I can provide them, but I think that it is not necessary because the cause was found.

Thanks.

EDIT:
When compiling wxWidgets without --prefix it is installed in /usr/local. So when I type wx-config --list in the terminal the system uses the one which is in /usr/local/bin. The same applies when building in Code::Blocks.

So, if I want to cross-compile under linux, I should compile all wxWidgets libraries by myself (and get it to work)... It seems that I will install Code::Blocks in windows.
« Last Edit: August 16, 2008, 01:44:08 am by Ganbito »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #43 on: August 16, 2008, 10:15:07 am »
If the wx-config does not list the correct entries, it's a wxWidgets install issue.
What does
Code
update-alternatives --list wx-config
show?

It should be something like:
Code
/usr/lib/wx/config/base-unicode-release-2.8
/usr/lib/wx/config/gtk2-unicode-release-2.8
.
If not it might be that you did not install the exWidgets-dev packages correctly.
You can try to uninstall your self-compiled wxwidgets by running "make uninstall" from its source directory.
And then reinstall all wxWidgets-packages.

You should eventually purge them first.

From synaptic chose "remove completely", maybe it's not the exact text, but it should be something like this (my system uses german language).

Then install:
"libwxbase2.8-0", "libwxbase2.8-dev", "libwxgtk2.8-0", "libwxgtk2.8-dev", "wx2.8-headers", "wx2.8-i18n", "wx-common", "libwxmsw2.8-dev", "wx2.8-headers-msw" and if you need due to dependencies of "wx2.8-headers-msw" you have to install "wx2.8-headers-msw-force-depends".
(The debug-packages of wxWidgets are only needed if you want to debug wxWidgets itself.)

And of course you need "mingw32" and its dependencies "mingw32-binutils" and "mingw32-runtime".

That's the installation that works out of the box on all my debian systems with the setup described in my wiki-article (even on clean systems, where I never build wxWidgets or C::B from source).

Offline Ganbito

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #44 on: August 16, 2008, 12:45:52 pm »
Code
update-alternatives --list wx-config
shows:

Code
/usr/lib/wx/config/base-unicode-release-2.8
/usr/lib/wx/config/gtk2-unicode-release-2.8
/usr/lib/wx/config/base-unicode-debug-2.8
/usr/lib/wx/config/gtk2-unicode-debug-2.8

I did a "make uninstall" and "remove completely" the wxWidgets libraries yesterday, but I will try another time.
....

I obtain the same.

Of course, I have installed "mingw32" and its dependencies, if don't I won't be able to cross-compile for windows, and I can.

I tried exactly your wiki-article after reinstalling (before building wxWidgets), and it don't work for me, it can be because my system is not Debian, but Debian-based (Ubuntu).