[SOLVED] wxWidgets 3.0.4 - App won't run in release form

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
dcbdbis
Knows some wx things
Knows some wx things
Posts: 31
Joined: Sun Nov 24, 2013 9:49 pm
Location: Aurora, Colorado

[SOLVED] wxWidgets 3.0.4 - App won't run in release form

Post by dcbdbis » Wed Aug 07, 2019 10:54 pm

Arch Linux. C::B 17:12. wx 3.0.4. gcc = 9.1.0, gdb = 8.3. Target platform = x64.

All packages from my distro's repo. Nothing built from scratch.

I have an app that compiles and runs just perfectly in the debug mode. But when I build the release version - it crashes with no error codes.

I launched it from the terminal to see if I could get any errors. This is all I get:

Code: Select all

Segmentation fault (core dumped)
And I have no idea where to begin looking to resolve it.

Again - the app works perfectly in debug builds. I just can't run it in release build. Not from within CB, nor from the CLI. I can also run the debug version from the CLI and it operates perfectly. The issue is unique to the release build.

I don't know if this is a wx issue, a CB issue, or a gcc issue.

Pointers regarding where to start looking would be appreciated.


Sincerely and respectfully,

Dave

Edits: Not five minutes after posting this - I turned off the O2 optimizations for the compiler. In fact I tried all optimizations (one at a time). Any optimization at all and the release build crashes. Turn off all optimizations, and the release build operates normally. Typically - I prefer to use the O2 optimizations when I build other packages from source.....???

Anyone have any ideas? I mean it's solved - but I'd sure like some hints from the more experienced wx users out there....

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3446
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxWidgets 3.0.4 - App won't run in release form

Post by ONEEYEMAN » Wed Aug 07, 2019 11:05 pm

Hi,
Install gdb and try to run it under gdb.

Code: Select all

gdb <you_program_name>
gdb> run
Segmentation fault
gdb> bt
See if you can narrow down where does it crashes.

Also, does it crash or the start or when you exit from application?
Does it executes any threads?
Does it open any sockets?

Thank you.

dcbdbis
Knows some wx things
Knows some wx things
Posts: 31
Joined: Sun Nov 24, 2013 9:49 pm
Location: Aurora, Colorado

Re: [SOLVED] wxWidgets 3.0.4 - App won't run in release form

Post by dcbdbis » Wed Aug 07, 2019 11:17 pm

Thank you for the reply.

gdb is of little benefit when the release build strips out the debugging symbols. And the compiler complains about optimizations turned on while building with the debug symbols.

It's a single-threaded app (at this time), it does not do any networking at all. It's a basic database app for an electrical contractor. (SQLite)

Again - the problem is solved by turning off all compiler optimizations for a release build. I am suspicious of the compiler as a result.

Thanks!


Dave

alys666
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 208
Joined: Tue Oct 18, 2016 2:31 pm

Re: [SOLVED] wxWidgets 3.0.4 - App won't run in release form

Post by alys666 » Fri Aug 09, 2019 2:10 am

Imo, it's a bug in your code due to global variables initialization order.
c++ has not modules and cannot correctly understand an order of initialization of compilation units.
when you change optimization option, it could change an order of initialization and it becomes wrong.
some global object B, to be initialized, needs already initialized A, but it's still not initialized.
as said, run the program under debugger and find out the place where the error occurs.
normally optimization cannot make a well written code wrong.
ubuntu 16.04, wxWidgets 3.0.4

alys666
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 208
Joined: Tue Oct 18, 2016 2:31 pm

Re: [SOLVED] wxWidgets 3.0.4 - App won't run in release form

Post by alys666 » Fri Aug 09, 2019 2:35 am

also, when you have optimization off, you are more tolerant to errors like - usage of uninitialized variables and function not returning result. so switch all warnings on, for gcc it's option -Wall -Wextra , and check for warnings like - usage of uninitialized variable, and function possibly(or definitely) not returning result.
anyway reasonable optimization cannot make you code not working.
ubuntu 16.04, wxWidgets 3.0.4

dcbdbis
Knows some wx things
Knows some wx things
Posts: 31
Joined: Sun Nov 24, 2013 9:49 pm
Location: Aurora, Colorado

Re: [SOLVED] wxWidgets 3.0.4 - App won't run in release form

Post by dcbdbis » Fri Aug 09, 2019 4:42 am

Perceptive....

I have some global variables in a class.... to be used (r/w) between frames and dialogs.

Although the program runs just fine in debug mode, and also runs just fine in release mode - as long as I don't optimize. In fact I ran it today for about 4 hours in the release mode, as a stand-alone binary outside of C::B, entering my clients project data into it....and there were no issues of any kind.

In fact I prefer the way it operates to it's C#.NET parent. I'm porting the clients app's (there are two) from C# to C++.

Almost all of my variables are from the heap - not the stack. I'm extremely careful to initialize them and delete them. My habit comes form the old dos days when the stack was small and it was easier to overload it - so I always use the heap. Have done so for decades. Old habits die hard..... That's not to assert that my code is perfect. There is no such thing as perfect code. There are always things we human beings miss. And I being > 63 years old - I am going to be more prone to errors than younger devs.

Question - In the gcc/Linux world - are there utilities (like I had under Visual Studio), that would analyze the code and uncover things as null pointers, uninitialized stuff, etc? And at some time - I will want to profile the code at runtime and polish it up and remove bottlenecks.

I am not a new coder. But am not as experienced as a Linux developer. I did a device driver once for AT&T Unix Sys V 3.3....But that was decades ago. And the C::B and the wxWidgets tool set - are both newer to me. I've only done a couple of small apps in them under the Windows environment. The two apps I'm working on now - are targeted for my client under Linux as they're moving their entire infrastructure to Linux. W10 is simply causing them too many issues. For me - I'm using Arch as my distro. They're using Debian.


I'll use the compiler flags mentioned here to see if they yield anything of interest tomorrow morning...


THANK YOU - all of you for your responses. I do very much appreciate it.

Dave

<edits> Clarified some of the wording....

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3446
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: [SOLVED] wxWidgets 3.0.4 - App won't run in release form

Post by ONEEYEMAN » Fri Aug 09, 2019 5:08 am

Hi,
Such tool is called valgrind.

Thank you.

alys666
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 208
Joined: Tue Oct 18, 2016 2:31 pm

Re: [SOLVED] wxWidgets 3.0.4 - App won't run in release form

Post by alys666 » Fri Aug 09, 2019 9:08 am

1. Dave, gcc and clang perform good static analysis of a code, but only for one compilation unit, and different -W.. options are for it. Clang mostly uses the same options as GCC, for compatibility.
2. Debug and Release modes by default are just different sets of compiler options, Release removes -g option(debugging info), and adds some optimization kinda -02.
3. at least gcc without optimization generates very lazy and slow code, but more tolerant to programming errors like uninited local variables and functions not returning results.
4. use highest level of warnings(-Wall -Wextra) in development and correct place of every warning, if in is not such innocent like unused variable(if you like to save it for future or some clarification) or unused static function in compilation unit.
5. to test your release under debugger, or set option -02 in your debug mode and start under debugger. or set -g option in Release and start under debugger.
Alex.
ubuntu 16.04, wxWidgets 3.0.4

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3446
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: [SOLVED] wxWidgets 3.0.4 - App won't run in release form

Post by ONEEYEMAN » Fri Aug 09, 2019 2:17 pm

Hi,
Also, keep in mind that, comparing to Windows, *nix/OSX uses the same CRT when doing debug/release builds.
So turning on all possible warnings should help you diagnose the issue.

Also, try to run your program under valgrind. It will help you diagnose some stuff. But you need to be careful - the tool produces a lot of false positives.

Thank you.

dcbdbis
Knows some wx things
Knows some wx things
Posts: 31
Joined: Sun Nov 24, 2013 9:49 pm
Location: Aurora, Colorado

Re: [SOLVED] wxWidgets 3.0.4 - App won't run in release form

Post by dcbdbis » Fri Aug 09, 2019 3:42 pm

Thank you, to all of you for the great support.

C# had made me lazy - there is no other way to put it.

Using the -Wall setting, I discovered that I had two variables that were not being initialized, and two member functions that were not returning values as defined in the function prototype.

I fixed all the warnings, including a couple of for loops that were mixing signed and unsigned int's in the comparison statement. I also set the C++11 std compiler flag.

Valgrind reports no memory leaks - I am very careful with the new and delete operators.

In the end when I was all done - I turned back on the -O2 optimizations - and it runs like a champ now optimized.

Thank you, this has been a great "tune-up" back into C++ from C#....and I learned some strategies for Linux, and learned a tad about Valgrind.

I'm also finding a "groove" with wxWidgets, in my transition from the VCL (Borland C++ Builder 6), and from .NET.

Once I got through the tab traversal stuff - the wxWidgets library is working quite well.


Sincerely and respectfully,

Dave

alys666
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 208
Joined: Tue Oct 18, 2016 2:31 pm

Re: [SOLVED] wxWidgets 3.0.4 - App won't run in release form

Post by alys666 » Fri Aug 09, 2019 5:04 pm

Glad to hear, that problem solved, Dave. Have switched on -Wall, -Wextra, in all your projects.
Good luck.
Alex
ubuntu 16.04, wxWidgets 3.0.4

Post Reply