Thread: Compiler seg fault

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    48

    Compiler seg fault

    When I go to compile my program two of the files compile fine, then it gets to a third and I get a segmentation fault (linux, it usually means that the program tries to access memory that is not legal for anyone who doesn't work on linux) created by the compiler when trying to compile the third file. Does anyone know what could cause the compiler to do this?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well without actual versions, error messages, code - what do you want me to say?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    The compiler might be running out of memory. How much RAM do you have?

    You can compile each source file individually and link them yourself. If a single source file is too big, split it into two files.

    On my Windows computer, I had to split up a 40,000 line program (generated by another one of my programs) into 3 files . . . and I have 256 MB of RAM.

    dwk

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    48
    Well, I'm compiling on a server, so I'm assuming it has quite a bit of RAM. Also, the file isn't that many lines, < 500.

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    48
    Oh, sorry, forgot to post what I'm compiling in. I'm using the GCC compiler (g++)
    The error:
    g++: Internal error: Segmentation fault (program cc1plus)

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by dwks
    The compiler might be running out of memory. How much RAM do you have?
    uh, a stone age OS !!!
    frankly do you think that will ever happen on a modern OS ?!?
    Virtual memory was invented for some reason

    but 40k lines ?!? whoa !
    where's what I get with 100k lines in MSVC++ 6
    a.c(65536) : warning C4049: compiler limit : terminating line number emission
    and gcc compiles the whole file, although it takes about 10 secs

  7. #7
    Registered User
    Join Date
    May 2005
    Posts
    48
    Uh, I don't have 40K lines, that was someone else. I have less than 500 in this particular file

  8. #8
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by Buckshot
    Uh, I don't have 40K lines, that was someone else. I have less than 500 in this particular file
    that reply wasn't to you.
    Try a different compiler or update your current one.

    EDIT:
    do this on your command line.
    Code:
    $ gcc -dumpversion
    I get 3.3.3
    Last edited by xErath; 06-14-2005 at 11:19 PM.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Still not seeing any useful information which might help solve the problem. Simply saying gcc isn't enough.

    > I have less than 500 in this particular file
    Make a copy of it, start hacking out blocks of code and find a small example which duplicates the problem. Post it here.

    And make sure you mention the gcc version number as well!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User
    Join Date
    May 2005
    Posts
    48
    Right, I'm not sure what the version number is (not versed enough in linux to check that). I don't even know where to start "hacking" parts out of the code, since I don't have any indication what is causing the cc1 program to seg fault except that it does it on one particular file.

  11. #11
    Registered User
    Join Date
    Dec 2004
    Location
    UK
    Posts
    109
    gcc -v should give you the version of gcc

    since you have no idea what is causing the error just remove everything but main() and test

    then add a bit at a time until you get the error.
    then take everything but that bit out and see if you still get the error.
    repeat until you are confident you found which part is to blame.

  12. #12
    Registered User
    Join Date
    May 2005
    Posts
    48
    There is no main, this is just a file that contains a whole bunch of functions. So should I just take out all the functions and see which one is doing it?

    gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-42)

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > So should I just take out all the functions and see which one is doing it?
    Yeah, that'll do for now.
    The basic idea is that you post something small here (which crashes your compiler), and we all try it using our compilers to try and work out whether it's your code, your compiler or just randomness in the universe which is the problem.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  14. #14
    Registered User
    Join Date
    May 2005
    Posts
    48
    Well I have no idea what is crashing it, so I guess Ill go through, function by function.

  15. #15
    Registered User
    Join Date
    May 2005
    Posts
    48
    I narrowed it down to one line that crashes the compiler:
    Code:
    actual.score = Score(actual, data);
    actual is a struct passed by reference to the function, data is also a struct.
    I've checked to make sure that score is a member, and it is.
    The Score function's declaration looks like:
    Code:
    double Score(AEE addeff, datavar data);
    and the declaration of the function that this line is in is:
    Code:
    void Create_data(AEE &actual, datavar &data, total_net &net, double fake_st_dev);
    The AEE struct is:
    Code:
    struct AEE
    {
        char name;
        int namelen;
        EE eff[MAX_EFF];
        int size;
        double score, mean, st_dev;
    };

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting a seg fault
    By ammochck21 in forum C Programming
    Replies: 11
    Last Post: 01-23-2009, 05:27 AM
  2. next_permutation seg fault
    By zxcv in forum C++ Programming
    Replies: 9
    Last Post: 12-14-2008, 07:40 AM
  3. seg fault
    By hka26 in forum C++ Programming
    Replies: 1
    Last Post: 10-08-2007, 01:38 AM
  4. Found a seg fault, but can't explain why i get it
    By misplaced in forum C++ Programming
    Replies: 11
    Last Post: 08-29-2005, 02:58 AM
  5. seg fault with strcmp
    By samps005 in forum C Programming
    Replies: 2
    Last Post: 05-04-2003, 04:32 PM