Program runs with gdb but does't run with ./ProgramName-Collection of common programming errors

You’re probably accessing uninitialized data or have some kind of memory corruption problem. This would explain the program behaving differently when run in the debugger – you’re seeing the results of undefined behavior.

Run your program through valgrind’s memcheck tool and see what it outputs. Valgrind is a powerful tool that will identify many runtime errors on Linux, including a full stack trace to the error.