Windows/Msys2 samples/minimal.exe give segmentation fault

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
BrianP
In need of some credit
In need of some credit
Posts: 6
Joined: Sun Jan 27, 2019 8:43 pm

Windows/Msys2 samples/minimal.exe give segmentation fault

Post by BrianP » Sun Jan 27, 2019 8:56 pm

Hello

I am a complete newbie with WxWidgets and c++. I am running eclipse on Mingw/Msys2 but this problem has nothign to do with my IDE. Using the ide and the pre-built binaries for MSW I can compile and run Wx version of helloworld.cpp.

However, in order to be able to debug my code I want to run gdb and when I try and run gbd on eclipse I get an error.

WxWidget documentation has a number of different approaches to building the libraries. I tried a bunch of those with confusing results (it is not abundantly obvious which one would do one or another),

I figured I would start from scratch and rebuild WxWidgets with debug enabled. I followed install.txt that comes with the source:

$ mkdir build-debug
$ ../configure --enable-debug
$ make

This generates numerous warnings but apparently no errors. (so much text it is hard to tell but the last line is
make[1]: Leaving directory '/c/wxWidgets-3.0.4/build-debug/utils/wxrc'


When I test the library build by building the minimal sample:
$ cd samples/minimal
$ make

This also generates no errors.

and then run ./minimal.exe I get a segmentation fault. I've tried a couple other samples with the same result.

I am running gcc version 8.2.1 20181214 (Rev1, Built by MSYS2 project) if that makes a difference.

Whatever my other issues are I believe the samples should work correctly since these are obviously not related to the IDE.

Thanks in advance for any advice/guidance.

New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 305
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: Windows/Msys2 samples/minimal.exe give segmentation fault

Post by New Pagodi » Sun Jan 27, 2019 10:04 pm

You don't have to use the configure/make system with msys2. You can just use the mingw make files instead. To do so just start the appropriate shell (MSYS2 MinGW 32-bit or MSYS2 MinGW 64-bit), change to the build folder of your wxWidgets set and enter a command like:

Code: Select all

mingw32-make -f makefile.gcc BUILD=debug SHARED=1
The build tool is called 'mingw32-make' with both MSYS2 MinGW 32 and MSYS2 MinGW 64. You can build with multiple threads using commands like:

Code: Select all

mingw32-make -f makefile.gcc BUILD=debug SHARED=1 setup_h
mingw32-make -f makefile.gcc BUILD=debug SHARED=1 -j8
You can see the full list of options that can be passed to the build command in the file $WXROOT/docs/msw/install.md

BrianP
In need of some credit
In need of some credit
Posts: 6
Joined: Sun Jan 27, 2019 8:43 pm

Re: Windows/Msys2 samples/minimal.exe give segmentation fault

Post by BrianP » Sun Jan 27, 2019 10:09 pm

Thank you so much for the reply!

I will give that a try. I guess I am old school in thinking that if software has a guide and you use the guide it should work the way the guide says. I had tried to follow the way you suggested (though perhaps not exactly so I'll try again). In the interim in docs/msw/install.txt it tells me to do something similar but (?) under a DOS terminal and I've started that process to see what happens.

I'll update when I find out what happens with the samples under DOS and if that doesn't work using your suggestion for Mingw.

Thanks again

New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 305
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: Windows/Msys2 samples/minimal.exe give segmentation fault

Post by New Pagodi » Sun Jan 27, 2019 10:11 pm

Having said that, I just tried to build with configue/make in msys2 and I didn't get a segfault when running the mimimal sample. I did however have to add the path to the libraries to the shell's path before the sample would run. Do you maybe have another set of wxWidgets libraries on your system path that the sample might have found instead of the libraries that were just built?

BrianP
In need of some credit
In need of some credit
Posts: 6
Joined: Sun Jan 27, 2019 8:43 pm

Re: Windows/Msys2 samples/minimal.exe give segmentation fault

Post by BrianP » Sun Jan 27, 2019 10:20 pm

Update:

I followed the instructions for building under dos in doc/msw/install.txt namely

(add C:\msys64\mingw64\bin to the path)

mingw32-make -j4 -f makefile.gcc clean
mingw32-make -j4 -f makefile.gcc

cd samples\minimal
mingw32-make -j4 -f makefile.gcc

gcc_mswud\minimal

and it worked!

The good news is the output of the makefile, ie

g++ -o gcc_mswud\minimal.exe gcc_mswud\minimal_sample_rc.o gcc_mswud\minimal_minimal.o -g -mthreads -L.\..\..\lib\gcc_lib -Wl,--subsystem,windows -mwindows -lwxmsw30ud_core -lwxbase30ud -lwxtiffd -lwxjpegd -lwxpngd -lwxzlibd -lwxregexud -lwxexpatd -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lwininet

Should provide me with settings I need for eclipse.

Thanks for your help. I will update with a new post when I get Eclipse debug going because I have been unable to find a solution on the web.

BrianP
In need of some credit
In need of some credit
Posts: 6
Joined: Sun Jan 27, 2019 8:43 pm

Re: Windows/Msys2 samples/minimal.exe give segmentation fault

Post by BrianP » Sun Jan 27, 2019 11:03 pm

Dear New Pagodi

Because I am new to the forum my replies are getting held up. I do have the wxWidgets pre-compiled bits installed on MingW so that might be a problem. Nevertheless, when my replies are posted, you'll see I was able to get it to work following the "make libraries from the DOS shell" method in doc/msw/install.txt.

This allowed me to look at the g++ command line make by the makefile for compiling and linking. I discovered that in the current version of eclipse, if I take the wxWIdgets "hello world" program (essentially minimal.exe) and set

include path

c:\wxWidgets-3.0.4\lib\gcc_lib\mswud
c:\wxWidgets-3.0.4\include

and
Library Path
C:\wxWidgets-3.0.4\lib\gcc_lib

and

Libraries
wxmsw30ud_core
wxbase30ud
wxtiffd
wxjpegd
wxpngd
wxzlibd
wxregexud
wxexpatd
kernel32
user32
gdi32
comdlg32
winspool
winmm
shell32
comctl32
ole32
oleaut32
uuid
rpcrt4
advapi32
wsock32
wininet

and set g++ linker options to -static -static-libgcc -static-libstdc++ -g -static-libgcc -static-libstdc++

I can not only build the wxWidgets hello world program I can debug it with Eclipse. The only problem I have is that I get a breakpoint at main() (I have no main() despite disabling stop on startup at main() in Windows Preferences. I will eventually figure that out.

By the way I spent the last 2 days trying to solve this. Its weird how right after you make a post you discover something.

Thanks again.


It is not clear to me if the resulting program will run without Msys2 but for my educational purposes this works fine for now.

Post Reply