ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Linux C question using the gcc compiler.
gcc -Wall -W my_c_code.c -o ouput_program
How do you deal with a segmentation error?
I get this segmentation error at compile time
so is it a syntax error of some kind?
There is no clue as to what line of code is
causing it, so the entire program is suspect.
It drives me nuts! How do you get rid of a
segmentation error?
is producing a segmentation fault, then it the problem is not in your program. Since its not being executed yet and segmentation faults occur at runtime.
This means that your gcc is getting a segmentation fault. This could possibly be because of corrupted installation of gcc or libraries.
I would not like to comment until I could see the code. As its only one source file could you please post it, or dump it at a location in my signature.
thanks
Hmmm interesting that two people think it's gcc. As i always use an ide and never the command line, could please explain why it's gcc and not the code?
What exactly is getting the SIGSEGV? Is it the compiler, during compilation, which may leave a large "gcc.core" file behind? Or is it your program, during execution, which probably leaves an "output_program.core" file? If it is gcc, which seems very very unlikely to me (unless you did some bleeding edge CVS installation), you may need to file a bug report. Otherwise try testing your output_program with a debugger: `gdb ./output_program` and type "run".
To dmail: a compiler / interpreter should never crash during compilation / execution. It'd be like your IDE crashing in the middle of a session. It shouldn't happen no matter how bad the code you pass into it is. The compiler exists to catch those sort of errors! And if it just dies then it's not doing its job.
Hmmm interesting that two people think it's gcc. As i always use an ide and never the command line, could please explain why it's gcc and not the code?
Because TS indicates that it's at compile time and not at runtime He/She might have informed us incorrectly, but till that time I agree that it's not the compiled program as it's not running and so it must be the compiler.
I got it fixed. There is nothing wrong with
gcc or even my ancient computer. It was the code.
I can't remember exactly what I did since I have
a habbit of panicing and trying everything at
once, but I think the problem was this:
I won't write all the code, only the stuff that
matters:
Defined a structure globally
struct my_structure {
float * big_array;
other stuff...
}
typedef struct my_structure STX;
This next line caused the segmentation error
stxp->big_array = temp_array;
I fixed this in main()
int main(void)
{
STX * my_structure_ptr;
The next two lines fixed the problem
STX the_structure;
my_structure_ptr = &the_structure;
Real dumb mistake! I should have caught it
right alway, but I suspected the everything else,
including the computer hardware. It's kind of
hard to admit to a mistake like this. It's so
stupid!
While changing code all over the program and
recompiling, I got all kinds of wierd errors.
One was even from a library I never heard of
before. ( Id.so or something like that )
I should have written it down.
I use the command line and the nano editor.
For debugging I use printf and /* */ all over.
Sometimes gdb or DDD. The IDEs I've tried
all seem to take a year to "configure" and
my little programs aren't worth the trouble.
Thanks to you all for your help.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.