segmentation error

This is a discussion on segmentation error within the C Programming forums, part of the General Programming Boards category; Hi,
I have some problems when compiling a program. I compile the program using:
gcc -o main main.c NN_ev3.a -lm, ...

segmentation error

Hi,
I have some problems when compiling a program. I compile the program using:
gcc -o main main.c NN_ev3.a -lm, but i get a segmentation error. I suspect that the eror lies in how i am defining global variables in my main function.

Two dozen source and header files - you really need to learn how to debug your own code.

A quick lesson.

1. Compile for debugginggcc -g -o main main.c NN_ev3.a -lm

Add the -g flag to all the compilations which generate your .a file as well.

2. Load program inside the debuggergdb ./main

3. Run the program(gdb) run

4. When it crashes, find out where you are(gdb) bt
'bt' is back-trace, it shows you all the nested function calls at the point where it crashed.
From here you can (read the manual)
- print variables (print)
- traverse the stack (up, down)
- set breakpoints for another run
When you know where it crashed, work out how it got to that state, then track back through the code to figure out how to avoid getting into that state in the first place.

A segmentation violation means the operating system has detected your code modifying some area of memory that is not allowed to be modified. In C code, there are many possible ways this can happen. The most common, practically, is a problem with handling of pointers or arrays - and this class of error occurs in many many forms. For example, dereferencing an uninitialised pointer, accessing the fifth element of an array that only has three elements.

If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.