C program compiled with cygwin in Windows works, segmentation fault under Linux. Is cygwin GCC 'bad'?

后端 未结 11 2105
半阙折子戏
半阙折子戏 2021-02-19 10:11

For my Programming 102 class we are asked to deliver C code that compiles and runs under Linux. I don\'t have enough spare space on my hard drive to install Linux alongside Wind

11条回答
  •  隐瞒了意图╮
    2021-02-19 11:06

    A segmentation fault is the result of accessing memory at a non-existent (or previously freed) address. What I find very interesting is that the code did NOT segfault under cygwin. That could mean that your program used a wild pointer to some other processes' address space and was actually able to read it (gasp), or (more likely) the code that actually caused the segfault was not reached until the program was run under Linux.

    I recommend the following:

    1. Paste your code as it is a very interesting problem
    2. Send a copy of this to the cygwin developers
    3. Get a cheap Linux VPS if you'll be required to produce more programs that run under Linux, it will make your life much easier.

    Once your working under Linux (i.e. shelled into your VPS), try working with the following programs:

    • GDB
    • Valgrind
    • strace

    Also, you can try libraries like electric fence to catch these kinds of things as they happen while your program is running.

    Finally, make sure -Wall is passed to gcc, you want the warnings it would convey.

提交回复
热议问题