Building a wxWidgets program in Code::Blocks

2019-05-06 20:27发布

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 :)

3条回答
Root(大扎)
2楼-- · 2019-05-06 21:16

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

查看更多
【Aperson】
3楼-- · 2019-05-06 21:18

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>
查看更多
虎瘦雄心在
4楼-- · 2019-05-06 21:30

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.

查看更多
登录 后发表回答