I need major help. My program will compile but when I run it I get a segmentation fault. I don't know how to run a debugger with multiple files. Could someone please find when this error occurs? My project is due in 2 hours.

Recommended Answers

All 15 Replies

That's an awful lot to expect someone to look at, and get you a response in your timeframe. Does the seg fault message give you any indication of where the problem lies? What have you done to track it down?

I know its a lot but I don't know really where to start troubleshooting it. The seg fault does not give me any info where the error is.

I know its a lot but I don't know really where to start troubleshooting it. The seg fault does not give me any info where the error is.

Then you need to either use a debugger and put breakpoints in and see what lines are reached before the program seg faults, or alternatively, add some cout statements that you will delete later to find out. For example:

int a[10];
cout << "Got this far\n";
a[3] = 5;
cout << "Got this far 2\n";
a[7] = 6;
cout << "Got this far 3\n";
a[15] = 7;
cout << "Got this far 4\n";

Depending on what displays, you know how far you got and you then know what line number seg faulted. Using a debugger is faster and there is nothing to delete, but cout statements work too. Just remember to delete them when you fix the code!

Well perhaps you could begin by using a debugger?
Do you even know what one is? I only ask because sometimes knowledge about even the existance of such things comes as a surprise to some people.

Or even telling us the sequence of commands which leads to a problem.
Say adding a contestant, then trying to remove them again.

I'll add cout statements. I know how to use a debugger, but for only a single file-not multiple files.

> but for only a single file-not multiple files.
How is this any different?
Open your file of choice, click in the margin at the place you want to stop, and add breakpoint.
Or if you're using a command line debugger, then perhaps
stop in classname::method

I thought I would get a linker error.

The only thing the debugger needs from the linker is a decent symbol table so it can find stuff out for you, and relate that back to your source code in a form you can understand.

Tried it and got linker errors to methods the linker could not find.

I think you need to post some actual text or images of these error messages.
Because that made no sense whatsoever.

Compiler: Default compiler
Executing  g++.exe...
g++.exe "H:\mylab3\Olympics.cpp" -o "H:\mylab3\Olympics.exe"   -g3  -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib" -g3 
C:\DOCUME~1\admin\LOCALS~1\Temp/ccwXbaaa.o(.text+0x1e1): In function `ZN8Olympics10FindEventRESsPNS_8ListNodeE':
H:/mylab3/Olympics.cpp:64: undefined reference to `Event::geteventname()'
C:\DOCUME~1\admin\LOCALS~1\Temp/ccwXbaaa.o(.text+0x572): In function `ZN8Olympics13AddContestantESsP10Contestanti':
H:/mylab3/Olympics.cpp:101: undefined reference to `Event::AddContestant(Contestant*, int)'
C:\DOCUME~1\admin\LOCALS~1\Temp/ccwXbaaa.o(.text+0x875): In function `ZN8Olympics16DeleteContestantESsSsSs':
H:/mylab3/Olympics.cpp:125: undefined reference to `Event::DeleteContestant(std::string, std::string)'
C:\DOCUME~1\admin\LOCALS~1\Temp/ccwXbaaa.o(.text+0xa15): In function `ZN8Olympics5PrintERSo':
H:/mylab3/Olympics.cpp:141: undefined reference to `Event::Print(std::ostream&)'
C:\DOCUME~1\admin\LOCALS~1\Temp/ccwXbaaa.o(.text+0xcd2): In function `ZN8Olympics10PrintEventERSoSs':
H:/mylab3/Olympics.cpp:166: undefined reference to `Event::Print(std::ostream&)'
C:\DOCUME~1\admin\LOCALS~1\Temp/ccwXbaaa.o(.text+0xfdd): In function `ZN8Olympics18PrintEventPositionERSoSsSsSs':
H:/mylab3/Olympics.cpp:192: undefined reference to `Event::PrintPosition(std::ostream&, std::string, std::string)'
C:\DOCUME~1\admin\LOCALS~1\Temp/ccwXbaaa.o(.text+0x1489): In function `ZN8Olympics15SwapContestantsESsSsSsSsSs':
H:/mylab3/Olympics.cpp:219: undefined reference to `Event::SwapContestants(std::string, std::string, std::string, std::string)'
C:\DOCUME~1\admin\LOCALS~1\Temp/ccwXbaaa.o(.text+0x1755): In function `ZN8Olympics15AddSortedEventRESsRPNS_8ListNodeE':
H:/mylab3/Olympics.cpp:234: undefined reference to `Event::Event()'
C:\DOCUME~1\admin\LOCALS~1\Temp/ccwXbaaa.o(.text+0x17e9):H:/mylab3/Olympics.cpp:235: undefined reference to `Event::setEventName(std::string)'
C:\DOCUME~1\admin\LOCALS~1\Temp/ccwXbaaa.o(.text+0x18c1):H:/mylab3/Olympics.cpp:242: undefined reference to `Event::geteventname()'
C:\DOCUME~1\admin\LOCALS~1\Temp/ccwXbaaa.o(.text+0x1979):H:/mylab3/Olympics.cpp:244: undefined reference to `Event::Event()'
C:\DOCUME~1\admin\LOCALS~1\Temp/ccwXbaaa.o(.text+0x1a0d):H:/mylab3/Olympics.cpp:245: undefined reference to `Event::setEventName(std::string)'
C:\Dev-Cpp\lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to `WinMain@16'
collect2: ld returned 1 exit status

Execution terminated

OK, so when you said "you'd ran it and it crashed", this was dis-information.

With linker errors, your program is going nowhere at all, and any mention of debuggers (which operate on the executable) is a moot point.

> g++.exe "H:\mylab3\Olympics.cpp"
I don't know how you set your project up, but it should have all 4 of your .cpp files listed as members of the project. At the moment, you only have one, and it thinks that's the whole program. Whereas in fact, it's just one of the classes.

From the command line, you would do
g++ Contestants.cpp Event.cpp main.cpp Olympics.cpp

In the make file log (after adding all the source files to the project), you should see something like
g++ -c Contestants.cpp
g++ -c Event.cpp
g++ -c main.cpp
g++ -c Olympics.cpp
g++ Contestants.o Event.o main.o Olympics.o

I don't believe there was any "dis-information" from "you'd ran it and it crashed" because before that statement I said my program compiled. Although, I should have been clearer about "multiple files". Once I figured I should have added my files to a project to run the debugger, the debugger was not working properly. It would state that the source code had been updated and needed to re-build. Then it would compile without errors. I would run the debugger and it would complain again that the source code was updated when I did nothing to the code at all. I just need to find a solution to my debugger issues to prevent this same situation on my next project.

I don't believe there was any "dis-information" from "you'd ran it and it crashed" because before that statement I said my program compiled. Although, I should have been clearer about "multiple files". Once I figured I should have added my files to a project to run the debugger, the debugger was not working properly. It would state that the source code had been updated and needed to re-build. Then it would compile without errors. I would run the debugger and it would complain again that the source code was updated when I did nothing to the code at all. I just need to find a solution to my debugger issues to prevent this same situation on my next project.

Wait, does it compile or does it not compile? The errors you listed all look like linker errors, so you wouldn't be able to run anything with or without a debugger, as Salem said. Do a full clean (i.e delete the executable program and all the .o files) and try compiling it again and see if it compiles without errors. If so, run it, don't worry about any debugger. If that all works, try using the debugger again. Is the code you originally attached the current code?

Where you able to find the problem? What was is and whats the solution?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.