wxGridStringTable in static library -> undefined reference 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
mza330
In need of some credit
In need of some credit
Posts: 2
Joined: Thu Sep 24, 2020 4:25 pm

wxGridStringTable in static library -> undefined reference

Post by mza330 »

Hi, I'd like to create a static library using wxGridStringTable. I've created 2 projects in C::B: a static library and wxwidgets gui app.
1. static library has one class

Code: Select all

class csvmodel {
...
        wxGridStringTable m_table;
};
The library compiles OK:

Code: Select all

mingw32-g++.exe -D__WXMSW__ -O2 -Wall -m32 -ID:\wxWidgets-3.0.5\include -ID:\wxWidgets-3.0.5\lib\gcc_lib\mswu -c R:\csvapp4\wxmodel\csvmodel.cpp -o obj\Release\csvmodel.o
ar.exe -r -s -T bin\Release\libwxmodel.a obj\Release\csvmodel.o
ar.exe -r -c -T bin\Release\libwxmodel.a -s -static-libstdc++ -static-libgcc -m32 
Output file is bin\Release\libwxmodel.a with size 5.57 KB
2. wxwidgets gui app links to above library.

but app can't compile:

Code: Select all

-------------- Build: Release in wxapp (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DwxUSE_UNICODE -Wall -O2 -m32 -ID:\wxWidgets-3.0.5\include -ID:\wxWidgets-3.0.5\lib\gcc_lib\mswu -I..\wxmodel -ID:\wxWidgets-3.0.5\include -ID:\wxWidgets-3.0.5\lib\gcc_lib\mswu -c R:\csvapp4\wxapp\wxappApp.cpp -o obj\Release\wxappApp.o
mingw32-g++.exe -LD:\wxWidgets-3.0.5\lib\gcc_lib -L..\wxmodel\bin\Release -LD:\wxWidgets-3.0.5\lib\gcc_lib\mswu -o bin\Release\wxapp.exe  obj\Release\wxappApp.o obj\Release\wxappMain.o obj\Release\resource.res -s -mthreads -static-libstdc++ -static-libgcc -m32  -lwxmsw30u_richtext -lwxbase30u_xml -lwxmsw30u_adv -lwxmsw30u_html -lwxmsw30u_core -lwxbase30u -lwxpng -lwxzlib ..\wxmodel\bin\Release\libwxmodel.a -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 -lwsock32 -lodbc32 -mwindows
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: ..\wxmodel\bin\Release\../../obj/release/csvmodel.o:csvmodel.cpp:(.text+0x27): undefined reference to `vtable for wxGridStringTable'
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: ..\wxmodel\bin\Release\../../obj/release/csvmodel.o:csvmodel.cpp:(.text+0x2e): undefined reference to `vtable for wxGridStringTable'
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: ..\wxmodel\bin\Release\../../obj/release/csvmodel.o:csvmodel.cpp:(.text+0x43): undefined reference to `wxGridStringArray::~wxGridStringArray()'
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: ..\wxmodel\bin\Release\../../obj/release/csvmodel.o:csvmodel.cpp:(.text+0x77): undefined reference to `vtable for wxGridStringTable'
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: ..\wxmodel\bin\Release\../../obj/release/csvmodel.o:csvmodel.cpp:(.text+0x7e): undefined reference to `vtable for wxGridStringTable'
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: ..\wxmodel\bin\Release\../../obj/release/csvmodel.o:csvmodel.cpp:(.text+0x93): undefined reference to `wxGridStringArray::~wxGridStringArray()'
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: ..\wxmodel\bin\Release\../../obj/release/csvmodel.o:csvmodel.cpp:(.text+0x9a): undefined reference to `wxGridTableBase::~wxGridTableBase()'
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: ..\wxmodel\bin\Release\../../obj/release/csvmodel.o:csvmodel.cpp:(.text+0x4f): undefined reference to `wxGridTableBase::~wxGridTableBase()'
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: ..\wxmodel\bin\Release\../../obj/release/csvmodel.o:csvmodel.cpp:(.text+0xca): undefined reference to `wxGridStringTable::wxGridStringTable()'
If I replace wxGridStringTable with wxString variable (in csvmodel class) everything compiles and works fine.
Any Idea?
p.s. my environment:
MinGW.org GCC Build-2. version 9.2.0
wxWidgets-3.0.5
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGridStringTable in static library -> undefined reference

Post by doublemax »

In the linker command line move your library libwxmodel in front of the wx libraries.

https://stackoverflow.com/questions/451 ... ors-in-gcc
Dependencies of static libraries against each other work the same - the library that needs symbols must be first, then the library that resolves the symbol.
Use the source, Luke!
mza330
In need of some credit
In need of some credit
Posts: 2
Joined: Thu Sep 24, 2020 4:25 pm

Re: wxGridStringTable in static library -> undefined reference

Post by mza330 »

It works! thanks a lot! 8)
Post Reply