Pinpoint a Segmentation Fault

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2009
Posts: 17
Reputation: axed is an unknown quantity at this point 
Solved Threads: 1
axed axed is offline Offline
Newbie Poster

Pinpoint a Segmentation Fault

 
0
  #1
Oct 31st, 2009
I wrote a program to solve a system of linear equations. It works fine with the VS compiler. But when I try to run it using Cygwin, I get a seg fault(core dumped). But it does not say where the seg fault is.
I am using the following commands:
to complie: g++ -Wall -o main.out main.cpp
to run: ./main.out

Is there an option that i can put while running so that I can know on which line the seg fault is.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 39
Reputation: niXman is an unknown quantity at this point 
Solved Threads: 10
niXman's Avatar
niXman niXman is offline Offline
Light Poster
 
0
  #2
Oct 31st, 2009
show the code.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,855
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 120
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso
 
0
  #3
Nov 1st, 2009
Try g++ -Wall file.c , I guess some of the apis you are using does not work with g++ .
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 397
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz
 
0
  #4
Nov 1st, 2009
The bovious thing to do is to run it in the debugger e.g. gdb or ddd
Compile with g++ -g -o Prog prog.cpp, and the run as ddd Prog . When it hits the seg-fault, use up until you see the problem (backtrace in gdb). It is likely that the fault is say in a sta

There is also another method that is much more rigerous, that is to use valgrind http://valgrind.org/. [Don't think this works on linux] But run your program with valgrind Prog and you get a long list of the memory you accessed without initializing and memory that you didn't free.
experience is the most expensive way to learn anything
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 17
Reputation: axed is an unknown quantity at this point 
Solved Threads: 1
axed axed is offline Offline
Newbie Poster
 
0
  #5
Nov 1st, 2009
Thanks a lot.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC