1

What could be the cause for a program to crash/exit before entering the main() function?

I am working on a project that was running normally. I added some code that uses boost threads, I updated the makefiles (CMakeLists.txt), and everything compiles and links without issues.

When I launch the executable, all I get is the prompt.

To check if the programs starts doing something, I add a cerr << "TEST" << endl as the first instruction in main(), and nothing is printed.

Of course when I try to print that string no threads are created, yet.

Putting a break point at the beginning of main() is useless.

System:
Windows 7, MinGW, GCC, cmake

4
  • 1
    You probably want to use gdb :) Commented Jul 20, 2013 at 17:39
  • 1
    Most likely the reason is in some static initialization or trying to load a not found DLL then. Commented Jul 20, 2013 at 17:50
  • any idea on how u fixed the issue? Commented Sep 24, 2014 at 7:31
  • @PriteshAcharya: as you can see from the accepted answer, I had issues in a global class constructor. Putting the breakpoint there helped me find the bug. Commented Oct 2, 2014 at 9:59

2 Answers 2

5

The problem is probably in some global class varible's constructor. They will be called before main.

Sign up to request clarification or add additional context in comments.

Comments

0

Another possible case is the output has been cached, and the process crash after enter main, please add flush output here after the out put line, or you can reapte print it 1000 times to make sure it doesn't cached.

In that case, the easy way is to run it in debugger, it will cache the error.

1 Comment

cerr is typically unbuffered, for this very reason. And in either case, the endl should flush the stream, at which point the message is sent, and will be output (barring a crash of the whole OS).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.