mingw being unable to compile wxwidgets Topic is solved

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
lpx
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sun Aug 13, 2017 4:54 am

mingw being unable to compile wxwidgets

Post by lpx »

I've recently downloaded codeblocks for GUI projects. I downloaded the newest MinGW from https://sourceforge.net/projects/mingw/ ... urce=files and installed MinGW. Then I installed MinGW32-make(gcc, g++ and gdb) and downloaded wxwidgets 3.0.3 from the official site(both zip and setup.exe). After creating directory C:\wxwidgets-3.0.3, I followed the instructions on https://wiki.wxwidgets.org/Compiling_wx ... with_MinGW.
I run "clean" first: mingw32-make -f makefile.gcc clean
then :mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=release
then the following error occurred:
c:\mingw\include\stdio.h:345:12: error:expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘__mingw__snprintf’
extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...);
^
makefile.gcc:5942: recipe for target 'gcc_mswu\wxtiff_tif_win32.o' failed
mingw32-make: *** [gcc_mswu\wxtiff_tif_win32.o] Error 1
I didn't find similar problems online. It seems as though the problem comes from c:\mingw\include\stdio.h
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: mingw being unable to compile wxwidgets

Post by doublemax »

Please try again with TDM-GCC which is known to work:
http://tdm-gcc.tdragon.net/download

Also, make sure you only have only one GCC version in your %PATH%
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: mingw being unable to compile wxwidgets

Post by PB »

I just tested building wxWidgets 3.0.3 (from 7z archive) with MinGW (GCC 5.3.0) using

Code: Select all

mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=release
and it worked flawlessly as expected.

I do not understand how you described installing MinGW, it appears as it was two steps: "... installed MinGW. Then I installed MinGW32-make(gcc, g++ and gdb)...."?
As doublemax suggests, make sure you have only one GCC compiler toolchain in the path. If your PATH is a mess, you could use the where command.
lpx
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sun Aug 13, 2017 4:54 am

Re: mingw being unable to compile wxwidgets

Post by lpx »

doublemax wrote:Please try again with TDM-GCC which is known to work:
http://tdm-gcc.tdragon.net/download

Also, make sure you only have only one GCC version in your %PATH%
It seems like my previous compiler didn't work. Using TDM-GCC solves the problem.
THANKS A LOT.
lpx
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sun Aug 13, 2017 4:54 am

Re: mingw being unable to compile wxwidgets

Post by lpx »

Thanks a lot, it seems that my previous compiler is not working as expected. The TDM-GCC can successfully makefile.
THANKS A LOT.

(BTW, I said I installed mingw, what i meant was i installed mingw-get only, there are no packages in the bin file)
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: mingw being unable to compile wxwidgets

Post by PB »

Sadly, I must confirm that wxWidgets (current master) does not build with the latest MinGW - GCC 6.3.0: I got the same error the OP had. I will report the issue on wxTrac.

Edit: Reported as https://trac.wxwidgets.org/ticket/17936
Cooper
In need of some credit
In need of some credit
Posts: 3
Joined: Sat Aug 19, 2017 6:42 pm

Re: mingw being unable to compile wxwidgets

Post by Cooper »

Hello all,

I've just encountered the same problem as OP and I suspect it's GCC issue. Here's a little workaround for the problem.

I'm compiling wxWidgets 3.1.0 with MinGW gcc 6.3.0-1 under Win10:

Code: Select all

Microsoft Windows [Version 10.0.15063]
(c) 2017 Microsoft Corporation. Wszelkie prawa zastrzeżone.

i:\Data\ProgramFiles\MinGW\bin>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=i:/data/programfiles/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --with-gmp=/mingw --with-mpfr --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --enable-libgomp --disable-libvtv --enable-nls
Thread model: win32
gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)
MinGW\bin is the only path set for PATH envar. I'm compiling the library with following parameters:

Code: Select all

i:\Data\ProgramFiles\wxWidgets\build\msw>mingw32-make -j4 -f makefile.gcc BUILD=release SHARED=0 UNICODE=1 MONOLITHIC=1 CXXFLAGS="-std=gnu++11"
Shortly stdio.h error occurs as OP mentioned:

Code: Select all

In file included from ../../src/tiff/libtiff/tiffio.h:257:0,
                 from ../../src/tiff/libtiff/tiffiop.h:59,
                 from ../../src/tiff/libtiff/tif_close.c:29:
i:\data\programfiles\mingw\include\stdio.h:345:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__mingw__snprintf'
 extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...);
Taking a look into stdio.h:345 we can see 8 XXprintf function declarations, all but snprintf are defined in stdio.h itself. So just comment out stdio.h:345, it's not referenced anywhere. Problem solved.

However later on another error occurs:

Code: Select all

g++ -c -o gcc_mswu\monolib_app.o  -O2 -mthreads  -DHAVE_W32API_H -D__WXMSW__   -DNDEBUG    -D_UNICODE -I..\..\lib\gcc_lib\mswu -I..\..\include  -W -Wall -DWXBUILDING -I..\..\src\tiff\libtiff -I..\..\src\jpeg -I..\..\src\png -I..\..\src\zlib -I..\..\src\regex -I..\..\src\expat\lib -I..\..\src\stc\scintilla\include -I..\..\src\stc\scintilla\lexlib -I..\..\src\stc\scintilla\src -D__WX__ -DSCI_LEXER -DLINK_LEXERS -DwxUSE_BASE=1   -Wno-ctor-dtor-privacy  -std=gnu++11 -MTgcc_mswu\monolib_app.o -MFgcc_mswu\monolib_app.o.d -MD -MP ../../src/msw/app.cpp
../../src/msw/app.cpp: In member function 'bool {anonymous}::wxConsoleStderr::DoInit()':
../../src/msw/app.cpp:380:11: error: '::AttachConsole' has not been declared
     if ( !::AttachConsole(ATTACH_PARENT_PROCESS) )
Searching for AttachConsole() in ../../src/msw/app.cpp we can see a comment in line 278:

Code: Select all

    Notice that console output is available in the GUI app only if:
    - AttachConsole() returns TRUE (which means it never works under pre-XP)
This means we can safely comment out app.cpp:380 and app.cpp:381 unless we are using pre-XP windows (are there any ?). wxWidgets 3.1.0 builds successfully then.

AttachConsole() is conditionaly declared in \MinGW\include\wincon.h based on _WIN32_WINNT definition, so again most likely it's not defined properly by MinGW. Instead of app.cpp modification we can extend wxWidgets compilation command to

Code: Select all

i:\Data\ProgramFiles\wxWidgets\build\msw>mingw32-make -j4 -f makefile.gcc BUILD=release SHARED=0 UNICODE=1 MONOLITHIC=1 CXXFLAGS="-std=gnu++11 -D_WIN32_WINNT=0x0600"
and wxWidgets is successfully compiled again. But that's more risky than app.cpp modification.

Hope that helps.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: mingw being unable to compile wxwidgets

Post by PB »

FWIW, the AttachConsole issue was fixed some time ago: https://github.com/wxWidgets/wxWidgets/ ... 8f34a4f4a7
Cooper
In need of some credit
In need of some credit
Posts: 3
Joined: Sat Aug 19, 2017 6:42 pm

Re: mingw being unable to compile wxwidgets

Post by Cooper »

PB wrote:AttachConsole issue was fixed
Well, looks like it's not included in 3.1.0 relese. Mentioned lines 36-43 are missing in gccpriv.h in 3.1.0 release and there's no wx/msw/winver.h file to fix _WIN32_WINNT definition.

I've downloaded "Windows ZIP (28 MB)" 3.1.0 source code for compilation.

Best regards
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: mingw being unable to compile wxwidgets

Post by PB »

Cooper wrote:
PB wrote:AttachConsole issue was fixed
Well, looks like it's not included in 3.1.0 relese.
Sorry, I assumed it was obvious from the link I posted, otherwise you would not encounter it. The issue was fixed in Jan 2017 while 3.1.0 was released in Feb 2016.
Cooper
In need of some credit
In need of some credit
Posts: 3
Joined: Sat Aug 19, 2017 6:42 pm

Re: mingw being unable to compile wxwidgets

Post by Cooper »

I noted "Feb 2016" release date of wx 3.1.0, but I confused the fix date "13 Jan" with "13 Jan 2016" so ... I expected 3.1.0 to be fixed already. Thanks for claryfying that.

I also noticed my findings were discussed in detail in other thread here ... last year, so there's no more to discuss here. Anyway thanks for your patience.

Best regards
Post Reply