Cannot Compile For Windows Target

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
alvindera97
Earned a small fee
Earned a small fee
Posts: 20
Joined: Sun Apr 12, 2020 6:11 pm

Cannot Compile For Windows Target

Post by alvindera97 » Mon May 11, 2020 7:28 am

I compiled wxWidgets source code as per the instructions described here https://wiki.wxwidgets.org/WxWindows_ap ... clipse/CDT. This is the process I went through for the compilation:

First I created a "windows_build" directory where I extracted all the files from the wxWidgets source code (i.e extracted wxWidgets source code directory: /home/alvindera/Downloads/wxWidgets-3.1.3. And directory for windows_build is: /home/alvindera/Downloads/wxWidgets-3.1.3/windows_build).

Then within the windows_build directory, I ran the following commands:

../configure --prefix=/usr/local/wxWidgets/wxMSW/Unicode/ --host=i686-w64-mingw32 --enable-unicode --with-msw --without-subdirs


After running the above command, I got this message:

Code: Select all

Configured wxWidgets 3.1.3 for `i686-w64-mingw32'

  Which GUI toolkit should wxWidgets use?                 msw
  Should wxWidgets be compiled into single library?       no
  Should wxWidgets be linked as a shared library?         yes
  Should wxWidgets support Unicode?                       yes (using wchar_t)
  What level of wxWidgets compatibility should be enabled?
                                       wxWidgets 2.8      no
                                       wxWidgets 3.0      yes
  Which libraries should wxWidgets use?
                                       STL                no
                                       jpeg               builtin
                                       png                builtin
                                       regex              builtin
                                       tiff               builtin
                                       lzma               no
                                       zlib               builtin
                                       expat              builtin
                                       libmspack          no
                                       sdl                no

Then continued with:

make -j3

sudo make install

After sudo make install finished, I got the output:

Code: Select all

 ------------------------------------------------------
 
 The installation of wxWidgets is finished.  On certain
 platforms (e.g. Linux) you'll now have to run ldconfig
 if you installed a shared library and also modify the
 LD_LIBRARY_PATH (or equivalent) environment variable.
 
 wxWidgets comes with no guarantees and doesn't claim
 to be suitable for any purpose.
 
 Read the wxWindows Licence on licencing conditions.
 
 ------------------------------------------------------

Thereafter, I ran:

sudo ldconfig

After that, I ran this (on the command line):
sudoedit /etc/ld.so.conf.d/wx.conf

Code: Select all

# Local libraries support - introduced for wx-wwidgets
#/usr/local/wxWidgets/wxGTK/Unicode/lib
/usr/local/wxWidgets/wxMSW/Unicode/lib
#/usr/local/wxWidgets/wxMSW/Unicode-static/lib
Thereafter I ran:

sudo make clean
At the end of sudo make clean is got this message indicating some sort of error:

Code: Select all

(cd samples && make clean)
/bin/sh: 1: cd: can't cd to samples
Makefile:13874: recipe for target 'clean' failed
make: [clean] Error 2 (ignored)
Finally I ran the command:
wx-config --help. This was the output:

Code: Select all

 wx-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--release] [--version-full]
           [--list] [--selected-config] [--host=HOST] [--toolkit=TOOLKIT]
           [--universal[=yes|no]] [--unicode[=yes|no]] [--static[=yes|no]]
           [--debug[=yes|no]] [--version[=VERSION]] [--basename] [--cc] [--cxx]
           [--cppflags [base]] [--cxxflags [base]] [--cflags]
           [--rescomp] [--linkdeps] [--ld] [--utility=UTIL]
           [--libs [LIBS...]] [--optional-libs [LIBS...]]

    wx-config returns information about the wxWidgets libraries available on
  your system.  It may be used to retrieve the information required to build
  applications using these libraries using --cppflags, --cxxflags, --cflags,
  and --libs options. And you may query the properties of this configuration
  using --query-{host,toolkit,widgetset,chartype,debugtype,version,linkage}.

    NOTE:    Usage of --debug and --query-debugtype are only relevant if you
  have any  versions prior to 2.9 installed  and use the --version option to
  select an earlier version.

    If multiple builds of wxWidgets  are available,  you can use the options
  --prefix, --host, --toolkit, --unicode, --static, --universal or --version
  to select from them.  The  --selected-config  option shows the name of the
  current configuration and --list  shows available alternatives which match
  specified criteria.  The  --utility  option returns the correct version of
  UTIL to use with the selected build.  The  --linkdeps  option returns only
  static libraries for your makefile link rule dependencies.

    The LIBS arguments (comma or space separated) may be used to specify the
  wxWidgets libraries that  you wish to use. The "std" label may be used  to
  import all libraries that would be used by default if none were  specified
  explicitly, e.g. wx-config --libs core,base. The "all" label may  be  used
  to  import  all libraries that have been compiled which are shown  in  the
  list  below.  The  --optional-libs parameter should be followed by  a list
  of  libs that should be linked to, but only if they are available.

  Available libraries in this build are:
  xrc stc richtext ribbon propgrid aui html qa adv core xml net base
Now the build and installation are complete. I try to compile my C++ file to create an executable for windows with this command:

g++ gp_and_cgpa_calculator.cpp `wx-config --cxxflags --libs --prefix=/usr/local/wxWidgets/wxMSW/Unicode --host=i686-w64-mingw32` -o gpCalculator.exe --verbose


And this is the output:

Code: Select all

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
g++: error: unrecognized command line option ‘-mthreads’; did you mean ‘-pthread’?
g++: error: unrecognized command line option ‘-mwindows’; did you mean ‘-m3dnow’?
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) 
At this point, I don't know if my command is wrong or if I must have done something wrong during the compilation as I followed all the instructions and no exception brought the compilation or installation to a halt. I have laid out all the processes I have gone through and still the same result. Please, assistance is needed.

Just to note: I am on Ubuntu 18.04
.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4230
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Cannot Compile For Windows Target

Post by ONEEYEMAN » Mon May 11, 2020 6:02 pm

Hi,
alvindera97 wrote:
Mon May 11, 2020 7:28 am
I compiled wxWidgets source code as per the instructions described here https://wiki.wxwidgets.org/WxWindows_ap ... clipse/CDT. This is the process I went through for the compilation:

First I created a "windows_build" directory where I extracted all the files from the wxWidgets source code (i.e extracted wxWidgets source code directory: /home/alvindera/Downloads/wxWidgets-3.1.3. And directory for windows_build is: /home/alvindera/Downloads/wxWidgets-3.1.3/windows_build).

Then within the windows_build directory, I ran the following commands:

../configure --prefix=/usr/local/wxWidgets/wxMSW/Unicode/ --host=i686-w64-mingw32 --enable-unicode --with-msw --without-subdirs


After running the above command, I got this message:

Code: Select all

Configured wxWidgets 3.1.3 for `i686-w64-mingw32'

  Which GUI toolkit should wxWidgets use?                 msw
  Should wxWidgets be compiled into single library?       no
  Should wxWidgets be linked as a shared library?         yes
  Should wxWidgets support Unicode?                       yes (using wchar_t)
  What level of wxWidgets compatibility should be enabled?
                                       wxWidgets 2.8      no
                                       wxWidgets 3.0      yes
  Which libraries should wxWidgets use?
                                       STL                no
                                       jpeg               builtin
                                       png                builtin
                                       regex              builtin
                                       tiff               builtin
                                       lzma               no
                                       zlib               builtin
                                       expat              builtin
                                       libmspack          no
                                       sdl                no

Then continued with:

make -j3

sudo make install

After sudo make install finished, I got the output:

Code: Select all

 ------------------------------------------------------
 
 The installation of wxWidgets is finished.  On certain
 platforms (e.g. Linux) you'll now have to run ldconfig
 if you installed a shared library and also modify the
 LD_LIBRARY_PATH (or equivalent) environment variable.
 
 wxWidgets comes with no guarantees and doesn't claim
 to be suitable for any purpose.
 
 Read the wxWindows Licence on licencing conditions.
 
 ------------------------------------------------------

Thereafter, I ran:

sudo ldconfig

After that, I ran this (on the command line):
sudoedit /etc/ld.so.conf.d/wx.conf
I believe that this step is unnecessary - "ldconfig" did this for you.
alvindera97 wrote:
Mon May 11, 2020 7:28 am

Code: Select all

# Local libraries support - introduced for wx-wwidgets
#/usr/local/wxWidgets/wxGTK/Unicode/lib
/usr/local/wxWidgets/wxMSW/Unicode/lib
#/usr/local/wxWidgets/wxMSW/Unicode-static/lib
Thereafter I ran:

sudo make clean
At the end of sudo make clean is got this message indicating some sort of error:
Why did you need cleaning the tree? Its OK to leave it there..
alvindera97 wrote:
Mon May 11, 2020 7:28 am

Code: Select all

(cd samples && make clean)
/bin/sh: 1: cd: can't cd to samples
Makefile:13874: recipe for target 'clean' failed
make: [clean] Error 2 (ignored)
This would have failed anyway - you didn't build the samples, just the library.
alvindera97 wrote:
Mon May 11, 2020 7:28 am
Finally I ran the command:
wx-config --help. This was the output:

Code: Select all

 wx-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--release] [--version-full]
           [--list] [--selected-config] [--host=HOST] [--toolkit=TOOLKIT]
           [--universal[=yes|no]] [--unicode[=yes|no]] [--static[=yes|no]]
           [--debug[=yes|no]] [--version[=VERSION]] [--basename] [--cc] [--cxx]
           [--cppflags [base]] [--cxxflags [base]] [--cflags]
           [--rescomp] [--linkdeps] [--ld] [--utility=UTIL]
           [--libs [LIBS...]] [--optional-libs [LIBS...]]

    wx-config returns information about the wxWidgets libraries available on
  your system.  It may be used to retrieve the information required to build
  applications using these libraries using --cppflags, --cxxflags, --cflags,
  and --libs options. And you may query the properties of this configuration
  using --query-{host,toolkit,widgetset,chartype,debugtype,version,linkage}.

    NOTE:    Usage of --debug and --query-debugtype are only relevant if you
  have any  versions prior to 2.9 installed  and use the --version option to
  select an earlier version.

    If multiple builds of wxWidgets  are available,  you can use the options
  --prefix, --host, --toolkit, --unicode, --static, --universal or --version
  to select from them.  The  --selected-config  option shows the name of the
  current configuration and --list  shows available alternatives which match
  specified criteria.  The  --utility  option returns the correct version of
  UTIL to use with the selected build.  The  --linkdeps  option returns only
  static libraries for your makefile link rule dependencies.

    The LIBS arguments (comma or space separated) may be used to specify the
  wxWidgets libraries that  you wish to use. The "std" label may be used  to
  import all libraries that would be used by default if none were  specified
  explicitly, e.g. wx-config --libs core,base. The "all" label may  be  used
  to  import  all libraries that have been compiled which are shown  in  the
  list  below.  The  --optional-libs parameter should be followed by  a list
  of  libs that should be linked to, but only if they are available.

  Available libraries in this build are:
  xrc stc richtext ribbon propgrid aui html qa adv core xml net base
Can you run the following:

Code: Select all

`wx-config --cxxflags --libs`
and post the output.
alvindera97 wrote:
Mon May 11, 2020 7:28 am
Now the build and installation are complete. I try to compile my C++ file to create an executable for windows with this command:

g++ gp_and_cgpa_calculator.cpp `wx-config --cxxflags --libs --prefix=/usr/local/wxWidgets/wxMSW/Unicode --host=i686-w64-mingw32` -o gpCalculator.exe --verbose


And this is the output:

Code: Select all

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
g++: error: unrecognized command line option ‘-mthreads’; did you mean ‘-pthread’?
g++: error: unrecognized command line option ‘-mwindows’; did you mean ‘-m3dnow’?
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) 
At this point, I don't know if my command is wrong or if I must have done something wrong during the compilation as I followed all the instructions and no exception brought the compilation or installation to a halt. I have laid out all the processes I have gone through and still the same result. Please, assistance is needed.

Just to note: I am on Ubuntu 18.04
.
Usually you need to supply 2 options - --host and --target to configure.
Please check the help for proper usage.

I believe one is for the platform you are compiling on and the other you are compiling for.

So you need to set them up accordingly.

Thank you.

alvindera97
Earned a small fee
Earned a small fee
Posts: 20
Joined: Sun Apr 12, 2020 6:11 pm

Re: Cannot Compile For Windows Target

Post by alvindera97 » Mon May 11, 2020 8:00 pm

Thanks for your reply and analysis of the situation. However, I would like to clarify something.

Are you referring to the output of

Code: Select all

g++ `wx-config --cxxflags --libs


As I got the result;

Code: Select all

/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux_gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4230
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Cannot Compile For Windows Target

Post by ONEEYEMAN » Mon May 11, 2020 8:14 pm

Hi,
No.

Just run:

Code: Select all

wx-config --cxxflags --libs
wx-config is a shell script.

alvindera97
Earned a small fee
Earned a small fee
Posts: 20
Joined: Sun Apr 12, 2020 6:11 pm

Re: Cannot Compile For Windows Target

Post by alvindera97 » Mon May 11, 2020 8:29 pm

ONEEYEMAN wrote:
Mon May 11, 2020 8:14 pm
Hi,
No.

Just run:

Code: Select all

wx-config --cxxflags --libs
wx-config is a shell script.
Thanks for the clarification. This is the output of the command:

Code: Select all

-I/usr/local/lib/wx/include/gtk3-unicode-3.1 -I/usr/local/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread
-L/usr/local/lib -pthread   -lwx_gtk3u_xrc-3.1 -lwx_gtk3u_html-3.1 -lwx_gtk3u_qa-3.1 -lwx_gtk3u_core-3.1 -lwx_baseu_xml-3.1 -lwx_baseu_net-3.1 -lwx_baseu-3.1 

alvindera97
Earned a small fee
Earned a small fee
Posts: 20
Joined: Sun Apr 12, 2020 6:11 pm

Re: Cannot Compile For Windows Target

Post by alvindera97 » Wed May 13, 2020 8:03 am

Unfortunately it seems like the cross-platform claim is not actually possible with wxWidgets. As all the research I have made don't seem to have a realistic solution. I believe that if wxWidgets truly and comfortably can "cross platform", there would be proper support and a forum genre for it. Apart from that, there is no practical (not that I've seen) tutorial on how to compile for different environments from another environment.

There was a particular forum topic that centered around this same topic and the best recommendation was to install Microsoft Visual Studio and compile there [in a windows environment]. However, all the code was written within a Linux environment. I don't understand this honestly. If compilation for windows would require the entire Windows SDK (as enforced by Microsoft Visual Studio), I would have been better off being told early.

Now after almost 2 moths of writing and debugging code, everyone goes cold turkey when it comes to Windows. Sadly. This might be my last post with this forum and my impression of cross compilation entirely. I have recently found out that the topic of cross compilation is treated poorly. Maybe one day, wxWidgets may decide to tell the world the real truth by removing "Cross Platform" from their site and every blog/article written about them and "cross platform compilation",

The forum was my last resort for sorting this out even after knowing very well what the outcome might be.

For those who answered my questions and suggested brilliantly, I am deeply grateful. If there can ever be a solution to this, please feel free to reply. If I wanted to get the entire Windows SDK to just compile one app for the first and last time in my life, I definitely wouldn't be here. So please, all discussions regarding Visual Studio is penny wise pound foolish to me.

For those who felt offended with this post, bear with me. I have written python code all my life and this is basically my first real experience with C++ (to think I started liking and recommending the language). Projects don't get abandoned or left in the cold like Java. The community would also let you know what works, what doesn't work and error messages are clear. Posting the results of all I've tried might still amount to nothing as "Windows" here is treated next to a joke....

Thanks again for the experience.

Adios!

User avatar
doublemax
Moderator
Moderator
Posts: 14952
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Cannot Compile For Windows Target

Post by doublemax » Wed May 13, 2020 11:57 am

wxWidgets is cross platform in the sense that you can build your applications on different platforms from the same source code. Cross platform compilation (e.g. building Windows executables under Linux) is a totally different issue and not primarily wxWidgets' concern.
Use the source, Luke!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4230
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Cannot Compile For Windows Target

Post by ONEEYEMAN » Wed May 13, 2020 4:09 pm

Hi,
As I said you should supply both "--host" and "--target" when you do cross-platform compilation, not cross-platform development.

Other than that - why not use a familiar language? There is a wxPython (a python binding of the library).

Thank you.

Post Reply