Building app using static wxwidgets libs gives linking error after compilation. 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
user-001
In need of some credit
In need of some credit
Posts: 2
Joined: Wed Mar 30, 2022 12:58 pm

Building app using static wxwidgets libs gives linking error after compilation.

Post by user-001 »

When i attempt to compile using dynamic library it works fine. But when i set the path to use static libs to generate single exe file it gives the following linking error.

Code: Select all

C:/wxWidgets-3.1.5/lib/gcc_lib/libwxmsw31u_stc.a(stclib_stc.o):stc.cpp:(.text+0x1a81): undefined reference to `Scintilla_LinkLexers'
C:/wxWidgets-3.1.5/lib/gcc_lib/libwxmsw31u_stc.a(stclib_stc.o):stc.cpp:(.rdata$.refptr._ZN10wxVListBox12ms_classInfoE[.refptr._ZN10wxVListBox12ms_classInfoE]+0x0): undefined reference to `wxVListBox::ms_classInfo'
C:/wxWidgets-3.1.5/lib/gcc_lib/libwxmsw31u_stc.a(stclib_PlatWX.o):PlatWX.cpp:(.text+0x952): undefined reference to `wxVarScrollHelperBase::VirtualHitTest(int) const'
C:/wxWidgets-3.1.5/lib/gcc_lib/libwxmsw31u_stc.a(stclib_PlatWX.o):PlatWX.cpp:(.text+0x11f5): undefined reference to `wxVListBox::IsSelected(unsigned long long) const'      
C:/wxWidgets-3.1.5/lib/gcc_lib/libwxmsw31u_stc.a(stclib_PlatWX.o):PlatWX.cpp:(.text+0x14d1): undefined reference to `wxVListBox::IsSelected(unsigned long long) const'      
C:/wxWidgets-3.1.5/lib/gcc_lib/libwxmsw31u_stc.a(stclib_PlatWX.o):PlatWX.cpp:(.text+0x513c): undefined reference to `wxVListBox::SetSelection(int)'
C:/wxWidgets-3.1.5/lib/gcc_lib/libwxmsw31u_stc.a(stclib_PlatWX.o):PlatWX.cpp:(.text+0x5160): undefined reference to `wxVListBox::SetSelection(int)'
C:/wxWidgets-3.1.5/lib/gcc_lib/libwxmsw31u_stc.a(stclib_PlatWX.o):PlatWX.cpp:(.text+0x765f): undefined reference to `wxVarScrollHelperBase::wxVarScrollHelperBase(wxWindow*)'
full error: https://pastebin.com/w8YKRzpZ


The cmake find package is of following type:

Code: Select all

find_package(wxWidgets REQUIRED gl aui core base stc OPTIONAL_COMPONENTS net)

if(wxWidgets_FOUND)
    include(${wxWidgets_USE_FILE})
    target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
endif()
I have attempted to make cmake use static libs by doing the following:

Code: Select all

set(CMAKE_BUILD_TYPE Static)
set(wxWidgets_CONFIGURATION Static)

#for using static libraries
set(wxWidgets_USE_STATIC 1)

The output of the cmake command is as following:

Code: Select all

cmake -B build -S . -G "MinGW Makefiles"
-- The CXX compiler identification is GNU 8.1.0
-- The C compiler identification is GNU 8.1.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found wxWidgets: C:/wxWidgets-3.1.5/lib/gcc_lib/libwxmsw31u_gl.a;C:/wxWidgets-3.1.5/lib/gcc_lib/libwxmsw31u_aui.a;C:/wxWidgets-3.1.5/lib/gcc_lib/libwxmsw31u_core.a;C:/wxWidgets-3.1.5/lib/gcc_lib/libwxbase31u.a;C:/wxWidgets-3.1.5/lib/gcc_lib/libwxmsw31u_stc.a;C:/wxWidgets-3.1.5/lib/gcc_lib/libwxbase31u_net.a;C:/wxWidgets-3.1.5/lib/gcc_lib/libwxpng.a;C:/wxWidgets-3.1.5/lib/gcc_lib/libwxtiff.a;C:/wxWidgets-3.1.5/lib/gcc_lib/libwxjpeg.a;C:/wxWidgets-3.1.5/lib/gcc_lib/libwxzlib.a;C:/wxWidgets-3.1.5/lib/gcc_lib/libwxregexu.a;C:/wxWidgets-3.1.5/lib/gcc_lib/libwxexpat.a;opengl32;glu32;winmm;comctl32;uuid;oleacc;uxtheme;rpcrt4;shlwapi;version;wsock32 (found version "3.1.5") found components: gl aui core base stc net png tiff jpeg zlib regex expat 
-- Configuring done
-- Generating done
-- Build files have been written to: D:/programming/Fandral/build
I am using minGw64 8.1.0 and cmake version 3.23.0-rc4.
PaulUK
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Nov 18, 2020 12:55 pm

Re: Building app using static wxwidgets libs gives linking error after compilation.

Post by PaulUK »

Did you resolve this issue? I'm having a similar problem, I think.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Building app using static wxwidgets libs gives linking error after compilation.

Post by PB »

Isn't the op issue just a wrong library order? If what is written in the FindwxWidgets cmake module documenation, the stc library definitely should not be listed last in find_package().

I also have no idea where did they come from with "wxWidgets_USE_STATIC 1".
user-001
In need of some credit
In need of some credit
Posts: 2
Joined: Wed Mar 30, 2022 12:58 pm

Re: Building app using static wxwidgets libs gives linking error after compilation.

Post by user-001 »

PB wrote: Mon Apr 18, 2022 9:08 am Isn't the op issue just a wrong library order? If what is written in the FindwxWidgets cmake module documenation, the stc library definitely should not be listed last in find_package().
Doesn't seem like it. Tried every order. The same error each time. And for the record it works perfectly with dynamic library and doesn't work even with MSVC if built statically.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Building app using static wxwidgets libs gives linking error after compilation.

Post by ONEEYEMAN »

Hi,
Are you able to build minimal sample with both compiler, either configured with CMake or using provided Makefile/solution file?

Thank you.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Building app using static wxwidgets libs gives linking error after compilation.

Post by PB »

Actually, there is an issue but it is a CMake issue, not wxWidgets issue.

CMake's FindwxWidgets module does not add the scintilla library itself (see CMake variable WX_scintilla(d)), which is needed by the stc library in the static build (i.e., do the same what is done for image libraries, expat, zlib, and regex). This can be easily proven by adding the scintilla library (and for GCC/clang also imm32 Windows library) to the generated project manually and seeing that the build errors disappear.

This bug should be reported to Kitware, which maintains the module.

When using static wxSTC (wxWidgets self-built with makefile) in a manually set-up project, everything is OK.
Similarly, when using CMake-generated project with add_subdir(), everything works as expected too.

EDIT: FWIW, I filed an issue: https://gitlab.kitware.com/cmake/cmake/-/issues/23519
Post Reply