Search code examples
c++cmakemingwwxwidgetscodelite

CodeLite and wxWidgets on Windows: build completes successfully but program crashes


On a Windows 7 virtual machine I set up a C++ build environment using the following:

  1. C:\usr\local\gcc-13.2.0 (from winlibs);
  2. C:\usr\local\cmake-3.27.6 (from KitWare);
  3. C:\usr\local\wxWidgets-3.2.2.1 (sources, from wxwidgets.org);
  4. C:\usr\local\codelite-17.6.0 (from codelite.org), built wxWidgets in the directory C:\usr\local\wxWidgets-3.2.2.1\build (directory was there already, seemed the right place), using the CMake and gcc executables above and using mingw32-make from the compiler directory.

The binaries are in lib\gcc_x64_dll under the wxWidgets directory, and the names of all the shared libraries end in _gcc_custom.dll.

Then to build a wxWidgets 'Hello World' example, in CodeLite:

  1. changed "Settings" - "Compiler Settings" to the just-installed gcc
  2. changed "Settings" - "GDB Settings" to gdb in the same directory
  3. added WXWIN=C:\usr\local\wxWidgets-3.2.2.1 and WXCFG=gcc_x64_dll\mswu to "Settings" -> "Environment Variables"
  4. open a new project "hello_wxwidget", Category "GUI", Type "wxWidgets GUI application", compiler and debugger as above, Build System "CodeLite Makefile Generator". This will generate standard code to make a simple wxFrame.

The program builds successfully! However, when I run it, the output in CodeLite is just "Program exited" (no error messages) and no window appears.

When I run it through the debugger, it says Debugger exited with the following error string: "During startup program exited with code 0xc0000135".

Without other errors and warnings and no call stack available, is it possible to find out what is not working here?

EDIT

Following advice by @Tsyvarev I have opened the .exe file in the program Explorer Suite, which shows its dependencies:

  1. libgcc_s_seh-1.dll,
  2. libstdc++-6.dll (both in C:\usr\local\gcc-13.2.0\bin but not found by CFF Explorer);
  3. KERNEL32.dll,
  4. ucrtbase.dll (both found in C:\Windows\system32);
  5. wxbase32u_gcc_custom.dll,
  6. wxmsw32u_core_gcc_custom.dll,
  7. wxmsw32u_xrc_gcc_custom.dll (all three in C:\usr\local\wxWidgets-3.2.2.1\libgcc_x64_dll but not found by CFF Explorer)

In my "Settings" -> "Global Settings" I have now added C:\usr\local\wxWidgets-3.2.2.1\lib\gcc_x64_dll; C:\usr\local\gcc-13.2.0\bin; to the "Library Path" and -lwxbase32u_gcc_custom; -lwxmsw32u_core_gcc_custom; -lwxmsw32u_xrc_gcc_custom; -llibgcc_s_seh-1; -llibstdc++-6 to the "Linker Options". To make the last option work I also need to rename libstdc++-6.dll.a in the compiler's lib directory, otherwise the .a clashes with the .so.

Compilation finishes successfully, program crashes. From the IDE as well as from the shell. The IDE (debugger) gives the "exit code" message and the shell says: "The program cannot start because libgcc_s_seh-1.dll is missing from your computer."

Does anyone know what is needed to be able to use those DLLs both during linking my program and for running it independently?

EDIT II

After putting the two directories C:\usr\local\gcc-13.2.0\bin (the DLLs of g++) and C:\usr\local\wxWidgets-3.2.2.1\lib\gcc_x64_dll (the DLLs of wxWidgets) to the path and restarting:

  1. the first run from the IDE neither produced an error, nor a window
  2. the first run from the shell produced a window (!)
  3. all runs after that from the IDE produced a window as well

So that finally seems to have done the trick! (though not really sure what happened at "1.")

Will do some more testing and then produce a nice bullet list.


Solution

  • In the end the comments by @Tsyvarev and @Igor helped me find the answer. The issue with building wxWidgets as shared libraries, which is normal in Linux but not in Windows, is that these libraries need to be in the system's (or the user's) Path environment variable. They could also be copied into every executable's directory, but that would defy the purpose of shared libraries!

    So my recipe for building GUIs with wxWidgets in CodeLite in Windows is:

    1. Download G++, CMake and CodeLite binaries and wxWidgets sources;
    2. Build wxWidgets with GCC and CMake (with wxBUILD_SHARED ticked);
    3. Set the compiler in CodeLite to the new GCC and set WXWIN and WXCFG to the wxWidgets source directory and the lib//mswu directory, respectively;
    4. Set the System Path environment variable so that it includes both the bin directory of the GCC compiler and the full path of the WXCFG directory's parent;
    5. Select a project type in CodeLite that is wxWidgets-aware: it will put the right compiler, linker and resources options in.

    In the end, no extra linker options are necessary for building, but if you want to use shared libraries as they were intended, they need to be reachable via the Path environment variable (there is no $LD_LIBRARY_PATH equivalent)

    I copied the result of steps 1-2 to another Windows 7 virtual machine and steps 3-5 were enough to get a wxFrame working.