4

I'm trying to build this wxWidgets sample program using Code::Blocks 12.11 but the build fails no matter what I try.

For example, the build log shows the following (the project is under X:\programming\c++\HelloWxWidgets):

mingw32-g++.exe -Wall -fexceptions -g -D_GNUWIN32_ -D_WXMSW_ -DwxUSE_UNICODE -D_WXDEBUG_ -IC:\libraries\wxWidgets-2.8.12.01\include -IC:\libraries\wxWidgets-2.8.12.01\contrib\include -IC:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib\mswud -c X:\programming\c++\HelloWxWidgets\hworld2.cpp -o obj\Debug2\hworld2.o mingw32-g++.exe -LC:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib -o bin\Debug2\HelloWxWidgets.exe obj\Debug2\hworld2.o -static-libgcc C:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib\libwxmsw28ud.a C:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib\libwxmsw28ud.a(monolib_window.o): In function ZN8wxWindow6UpdateEv': C:\BuildAgent\work\wxPack\wxwidgets\build\msw/../../src/msw/window.cpp:1643: undefined reference toGdiFlush@0' C:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib\libwxmsw28ud.a(monolib_window.o): In function ZNK8wxWindow13GetTextExtentERK8wxStringPiS3_S3_S3_PK6wxFont': C:\BuildAgent\work\wxPack\wxwidgets\build\msw/../../src/msw/window.cpp:2132: undefined reference toGetTextExtentPoint32W@16' C:\BuildAgent\work\wxPack\wxwidgets\build\msw/../../src/msw/window.cpp:2133: undefined reference to `GetTextMetricsW@8'

And these are some of the build messages that I get

C:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib\libwxmsw28ud.a(monolib_window.o)||In function ZN8wxWindow6UpdateEv':| C:\BuildAgent\work\wxPack\wxwidgets\build\msw\..\..\src\msw\window.cpp|1643|undefined reference toGdiFlush@0'| C:\libraries\wxWidgets-2.8.12.01\lib\gcc_lib\libwxmsw28ud.a(monolib_window.o)||In function ZNK8wxWindow13GetTextExtentERK8wxStringPiS3_S3_S3_PK6wxFont':| C:\BuildAgent\work\wxPack\wxwidgets\build\msw\..\..\src\msw\window.cpp|2132|undefined reference toGetTextExtentPoint32W@16'| C:\BuildAgent\work\wxPack\wxwidgets\build\msw....\src\msw\window.cpp|2133|undefined reference to `GetTextMetricsW@8'|

Here are the full build log and all of the build messages (by the way, I don't have a C:\BuildAgent directory)

I am using wxPack 2.8.12 (installed in C:\libraries\wxWidgets-2.8.12.01) and GCC 4.7.2 (installed separately from Code::Blocks in C:\mingw using mingw-get )

Here are the build options in Code::Blocks

Thank you in advance of your help :)

maddouri
  • 3,737
  • 5
  • 29
  • 51
  • Those function definitions are in gdi32.lib. – chris Mar 05 '13 at 21:19
  • Yep. Sounds like gdi32 isn't being linked in. Make sure it and its directory are listed in the appropriate build settings. (There should be a list of libraries to include and paths to search for them.) – cHao Mar 05 '13 at 21:19

3 Answers3

4

Alright, I finally managed to get it working :)

I'm posting here the procedure to follow if, like me, someone wanted to use wxWidgets in an (initially) console project under Code::Blocks. With this, anyone should be able to build/run at least this sample code in a Wind0ws environment:

  1. I'll assume that Code::Blocks and MinGW are correctly setup.
  2. Download/Install wxMSW from http://www.wxwidgets.org/downloads/ (in my case, I downloaded wxMSW-2.8.12-Setup.exe and installed it in C:\libraries\wxWidgets-2.8.12)
  3. Open a command prompt, wxWidgets needs to be built, I'll take the exemple of a statically-linked, monolithic, debug build that uses unicode (more infos here):

    cd /D C:\libraries\wxWidgets-2.8.12\build\msw

    mingw32-make -f makefile.gcc BUILD=debug SHARED=0 MONOLITHIC=1 UNICODE=1

    :(mingw32-make will take some time to build the library)

  4. Open Code::Blocks

  5. Create a new console project, or if you already have a console project (and you plan to add a wxWidgets GUI to it) open it
  6. Right-click on the project > Build options
  7. Here are the build options that I used for the Debug build. Code::Blocks build options for wxWidgets
  8. Build & Run

[EDIT] wx/app.h should be included in addition to wx/wx.h

#include <wx/wx.h>
#include <wx/app.h>
maddouri
  • 3,737
  • 5
  • 29
  • 51
  • Or simply `-mwindows` linker flag. But then you loose the terminal window, which is good for debugging. You can combine `-mwindows -mconsole` also. – user877329 Jul 19 '15 at 17:38
0

You probably need to add following libs to linker settings (I took the list from VS 2012 but for GCC should be the same, you will need to add -luuid -luser32 .... to linker advanced options)

kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

UPD: can see taht chris suggested to add gdi32 lib. Looks reasonable for me. At least missing functions from your logs are defined there.

T-Rex
  • 874
  • 1
  • 6
  • 20
  • I added the libs in the [linker settings](http://i49.tinypic.com/i3if5y.png) but I still get the same errors. – maddouri Mar 05 '13 at 21:34
  • These libs should be listed after wx libs in linker command line. Please ensure that wx libs come first and then come libs on which wx libs depend. Also have you tried to create the wxWidgets project using Code::Blocks built-in wxWidgets project template and check new project's linker settings? – T-Rex Mar 05 '13 at 21:56
  • I created another project using Code::Blocks built-in wxWidgets project template: it builds without errors, but the application crashes (no windows are displayed, and it returns immediately after launching (Process terminated with status -1073741819 (0 minutes, 8 seconds) ) – maddouri Mar 05 '13 at 22:03
  • Have you tried to: 1) Use pre-built version of wxWidgets which comes with Code::Blocks? 2) Clean wx libs and rebuild from scratch? 3) Run your app from Windows Explorer and check whether it produces some meaningful error message? 4) Open the executable with Dependency Walker and check whether there are any missing DLLs on which app references? It can be so that you need to put mingwm10.dll into some folder which is accessible from PATH environment variable (or put it near EXE file) https://www.google.com.ua/search?q=mingwm10.dll%20wxWidgets – T-Rex Mar 05 '13 at 22:14
  • Thank you again for your help. I got tired of trying the little hacks I found when googling, so I downloaded [wx-config for windows](https://sites.google.com/site/wxconfig/) and added it to the PATH. I used the exact settings of the built-in code::blocks wxWidgets project template. I just changed the compiler settings > other options to `wx-config --cxxflags` and used `wx-config --libs` in linker settings > other linker options. Now I get another set of problems. Here you can check the [build log](http://pastebin.com/aMS93wNM) and the [build messages](http://pastebin.com/r0tYXsr9) – maddouri Mar 05 '13 at 22:26
  • Are you sure that you are using monolithic build of wxWidgets? I mean, you have only one lib wxmsw28 and not the set of specialized libs like wxbase28, wxmsw28_core, wxmsw28_adv etc? Also could you check whether you are using Unicode build of wx? I can see that compiler has -DwxUSE_UNICODE macro but in this case your lib's name should be with `u` suffix as far as I understand. Should be like `wxmsw28u`. – T-Rex Mar 05 '13 at 22:43
  • I published a video which shows how to build wxWidgets 2.8 and use it with CodeBlocks some time ago at http://wxwidgets.info/wxwidgets28_and_codeblocks_video_win-2/, maybe you could try to follow that instructions and compile libs and your app according to them? – T-Rex Mar 05 '13 at 22:46
0

I found a best way is that add ``wx-config --libs all` in your "other liner options" ,On this ,many issue will gone.

wxconfig screen shot

andrew
  • 21
  • 5