Author Topic: Static linking WXwidget project  (Read 6627 times)

sard

  • Guest
Static linking WXwidget project
« on: September 30, 2006, 12:50:02 pm »
I have built WXwidgets with mingw and the default shared option.  The minimal sample and my own hello world in Code Blocks works fine.

In a completely seperate directory I then built WXwidgets statically and again the minimal sample works fine.  This time thought my hello world app fails.

Code
-------------- Build: Debug in wxtest ---------------
Compiling: main.cpp
Linking console executable: .\wxtest.exe
obj\Debug\main.o(.text+0x17): In function `ZN8wxObject19ReservedObjectFunc3Ev':
C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp___ZN12wxAppConsole17CheckBuildOptionsEPKcS1_'
obj\Debug\main.o(.text+0x6c): In function `WinMain':
D:/cpp/wxtest/wxtest/main.cpp:297: undefined reference to `_imp___Z7wxEntryP11HINSTANCE__S0_Pci'
obj\Debug\main.o(.text+0x96): In function `ZN13HelloWorldApp6OnInitEv':
D:/cpp/wxtest/wxtest/main.cpp:29: undefined reference to `_imp__wxFrameNameStr'
obj\Debug\main.o(.text+0xc9):D:/cpp/wxtest/wxtest/main.cpp:29: undefined reference to `_imp__wxDefaultSize'
obj\Debug\main.o(.text+0xd2):D:/cpp/wxtest/wxtest/main.cpp:29: undefined reference to `_imp__wxDefaultPosition'
obj\Debug\main.o(.text+0x110):D:/cpp/wxtest/wxtest/main.cpp:30: undefined reference to `_imp__wxStatusLineNameStr'
obj\Debug\main.o(.text$_ZN13HelloWorldAppC1Ev[HelloWorldApp::HelloWorldApp()]+0xd): In function `ZN8wxObject19ReservedObjectFunc3Ev':
C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp___ZN5wxAppC2Ev'
obj\Debug\main.o(.text$_ZN12wxAppConsole11GetInstanceEv[wxAppConsole::GetInstance()]+0x4):C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp___ZN12wxAppConsole14ms_appInstanceE'
obj\Debug\main.o(.text$_ZN7wxFrameC1EP8wxWindowiRK8wxStringRK7wxPointRK6wxSizelS4_[wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&)]+0xd):C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp___ZN11wxFrameBaseC2Ev'
obj\Debug\main.o(.text$_ZN7wxFrameC1EP8wxWindowiRK8wxStringRK7wxPointRK6wxSizelS4_[wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&)]+0x17):C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp___ZTV7wxFrame'
obj\Debug\main.o(.text$_ZN7wxFrameC1EP8wxWindowiRK8wxStringRK7wxPointRK6wxSizelS4_[wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&)]+0x27):C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp___ZN7wxFrame4InitEv'
obj\Debug\main.o(.text$_ZN7wxFrameC1EP8wxWindowiRK8wxStringRK7wxPointRK6wxSizelS4_[wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&)]+0x65): In function `WinMain':
D:/cpp/wxtest/wxtest/main.cpp:297: undefined reference to `_imp___ZN7wxFrame6CreateEP8wxWindowiRK8wxStringRK7wxPointRK6wxSizelS4_'
obj\Debug\main.o(.text$_ZN12wxStringBaseC2EPKc[wxStringBase::wxStringBase(char const*)]+0x7): In function `ZN8wxObject19ReservedObjectFunc3Ev':
C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp___ZN12wxStringBase4nposE'
obj\Debug\main.o(.text$_ZN12wxStringBaseC2EPKc[wxStringBase::wxStringBase(char const*)]+0x27):C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp___ZN12wxStringBase8InitWithEPKcjj'
obj\Debug\main.o(.text$_ZN12wxAppConsole22SetInitializerFunctionEPFPS_vE[wxAppConsole::SetInitializerFunction(wxAppConsole* (*)())]+0x5):C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp___ZN12wxAppConsole12ms_appInitFnE'
obj\Debug\main.o(.text$_ZNK9wxAppBase12GetTopWindowEv[wxAppBase::GetTopWindow() const]+0x1b):C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp__wxTopLevelWindows'
obj\Debug\main.o(.text$_ZNK9wxAppBase12GetTopWindowEv[wxAppBase::GetTopWindow() const]+0x2c):C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp__wxTopLevelWindows'
obj\Debug\main.o(.text$_ZN13HelloWorldAppD1Ev[HelloWorldApp::~HelloWorldApp()]+0x16):C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp___ZN5wxAppD2Ev'
obj\Debug\main.o(.text$_ZN13HelloWorldAppD0Ev[HelloWorldApp::~HelloWorldApp()]+0x16):C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp___ZN5wxAppD2Ev'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_base-2.6.a(baselib_filename.o)(.text+0x17a5):filename.cpp: undefined reference to `CoCreateInstance@20'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_base-2.6.a(baselib_filename.o)(.text+0x17c7):filename.cpp: undefined reference to `IID_IPersistFile'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_base-2.6.a(baselib_wxchar.o)(.text+0x46):wxchar.cpp: undefined reference to `mbsrtowcs'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_base-2.6.a(baselib_wxchar.o)(.text+0x68):wxchar.cpp: undefined reference to `mbsrtowcs'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_base-2.6.a(baselib_wxchar.o)(.text+0xb6):wxchar.cpp: undefined reference to `wcsrtombs'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_base-2.6.a(baselib_wxchar.o)(.text+0xd8):wxchar.cpp: undefined reference to `wcsrtombs'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_app.o)(.text+0x6d5):app.cpp: undefined reference to `InitCommonControls@0'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_app.o)(.text+0x6f0):app.cpp: undefined reference to `OleInitialize@4'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_app.o)(.text+0x91e):app.cpp: undefined reference to `OleUninitialize@0'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_gdiimage.o)(.text+0x1394):gdiimage.cpp: undefined reference to `GetObjectA@12'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_gdiimage.o)(.text+0x15e1):gdiimage.cpp: undefined reference to `DeleteObject@4'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_gdiimage.o)(.text+0x164b):gdiimage.cpp: undefined reference to `DeleteObject@4'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_gdiimage.o)(.text+0x1793):gdiimage.cpp: undefined reference to `DeleteObject@4'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_gdiimage.o)(.text+0x17d2):gdiimage.cpp: undefined reference to `DeleteObject@4'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_gdiimage.o)(.text+0x1891):gdiimage.cpp: undefined reference to `GetObjectA@12'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_gdiimage.o)(.text+0x18bb):gdiimage.cpp: undefined reference to `DeleteObject@4'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_gdiimage.o)(.text+0x18e1):gdiimage.cpp: undefined reference to `DeleteObject@4'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x189b):window.cpp: undefined reference to `wxSystemOptions::GetOptionInt(wxString const&)'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x280a):window.cpp: undefined reference to `SelectObject@8'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x2829):window.cpp: undefined reference to `GetTextMetricsA@8'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x2845):window.cpp: undefined reference to `SelectObject@8'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x29e8):window.cpp: undefined reference to `SelectObject@8'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x2a1e):window.cpp: undefined reference to `GetTextExtentPoint32A@16'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x2a36):window.cpp: undefined reference to `GetTextMetricsA@8'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x2a98):window.cpp: undefined reference to `SelectObject@8'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x2b37):window.cpp: undefined reference to `SelectObject@8'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x5e85):window.cpp: undefined reference to `SelectPalette@12'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x5eb3):window.cpp: undefined reference to `RealizePalette@4'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x5eed):window.cpp: undefined reference to `SelectPalette@12'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x5f15):window.cpp: undefined reference to `RealizePalette@4'
C:\wxWidgets-2.6.3\build-ok\lib\libwx_msw_core-2.6.a(corelib_window.o)(.text+0x6224):window.cpp: undefined reference to `SelectPalette@12'
Process terminated with status 1 (0 minutes, 13 seconds)
50 errors, 0 warnings
const&)]+0x27):C:/wxWidgets-2.6.3/include/wx/object.h: undefined reference to `_imp___ZN7wxFrame4InitEv'

If I link with libwx_base-2.6.dll.a and libwx_msw_core-2.6.dll.a it works.  If I link with libwx_base-2.6.a and libwx_base-2.6.dll.a I get the error above.

The other linker options are -mthreads  -lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool -lwinmm -lshell32 -lcomctl32 -lcomdlg32 -lctl3d32 -ladvapi32 -lwsock32 -lgdi32

Any ideas?

Offline David Perfors

  • Developer
  • Lives here!
  • *****
  • Posts: 560
Re: Static linking WXwidget project
« Reply #1 on: September 30, 2006, 12:57:50 pm »
If I link with libwx_base-2.6.a and libwx_base-2.6.dll.a I get the error above.
Shouldn't that be libwx_base-2.6.a and libwx_core-2.6.a? (probably a type?)
You have to put those files in the exact order. First libwxmsw26_core.a than libwxbase26.a and then thos other options...

btw. this is no Code::Blocks problem, so if you have more questions about wxWidgets, you could better ask it at the wxForum... ;)
« Last Edit: September 30, 2006, 12:59:47 pm by mispunt »
OS: winXP
Compiler: mingw
IDE: Code::Blocks SVN WX: 2.8.4 Wish list: faster code completion, easier debugging, refactoring

sard

  • Guest
Re: Static linking WXwidget project
« Reply #2 on: September 30, 2006, 01:44:06 pm »
Thank you for the quick reply.

First of all I just managed to compile my hello world app successfully and nearly fell off my seat with shock!  :shock:

After 3 days of trial and error and grepping for missing references in .a files, here is the golden list of linker options you need for mingw.  The order was the last thing I was missing.

-lwx_msw_core-2.6
-lwx_base-2.6
-mthreads
-lrpcrt4
-loleaut32
-lole32
-luuid
-lwinspool
-lwinmm
-lshell32
-lcomctl32
-lcomdlg32
-lctl3d32
-ladvapi32
-lwsock32
-lgdi32
-lmingwex


After optimising for size and some UPX magic I have a beautiful 618 KB self contained app  8)

Now I can finally start learning the WX API.  I wish building and linking third party libraries wasn't so difficult.  Boost took me days to get working too  :oops:

I did originally post this in the wxwidget forums but I was wondering if there were any Code::Block specific settings I was missing.

Right, time to burn this project file to CD and shove it in a safety deposit box because I never want to go through that again  :lol:

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2777
Re: Static linking WXwidget project
« Reply #3 on: September 30, 2006, 02:12:08 pm »
Thank you for the quick reply.

First of all I just managed to compile my hello world app successfully and nearly fell off my seat with shock!  :shock:

After 3 days of trial and error and grepping for missing references in .a files, here is the golden list of linker options you need for mingw.  The order was the last thing I was missing.

-lwx_msw_core-2.6
-lwx_base-2.6
-mthreads
-lrpcrt4
-loleaut32
-lole32
-luuid
-lwinspool
-lwinmm
-lshell32
-lcomctl32
-lcomdlg32
-lctl3d32
-ladvapi32
-lwsock32
-lgdi32
-lmingwex


After optimising for size and some UPX magic I have a beautiful 618 KB self contained app  8)

Now I can finally start learning the WX API.  I wish building and linking third party libraries wasn't so difficult.  Boost took me days to get working too  :oops:

I did originally post this in the wxwidget forums but I was wondering if there were any Code::Block specific settings I was missing.

Right, time to burn this project file to CD and shove it in a safety deposit box because I never want to go through that again  :lol:

I understand your pain. Many of us have been stung by this also.

But for the record and benefit of others,  many of the sample programs show the correct linking order.