Search code examples
gccsegmentation-faultcygwinld

collect2: error: ld terminated with signal 11 [Segmentation fault], core dumped


I was learning OpenGL using GLFW, and didn't have a great understanding of makefiles at the time. I had OpenGL working, but I decided to learn makefiles more. I came up with this after a lot of websites, hours, and trial and error:

EXENAME = "OpenGL Demo"
CC = gcc
SRCS = ../src/OpenGLDemo.c
OBJS = $(SRCS: .c = .o)
CFLAGS = -Wall -g -c
LIBS = -L./libs -lglfw3 C:/Windows/SysWOW64/opengl32.dll C:/Windows/SysWOW64/glu32.dll

all: opengldemo exe

exe: $(OBJS)
    $(CC) $(OBJS) -o $(EXENAME) $(LIBS)

opengldemo: ../src/OpenGLDemo.c
    $(CC) $(CFLAGS) ../src/OpenGLDemo.c

clean:
    rm -f $(EXENAME)

rebuild: clean all

But, when I compile, it gives this error when it tries to build the executable:

collect2: error: ld terminated with signal 11 [Segmentation fault], core dumped
makefile:11: recipe for target 'exe' failed
make: *** [exe] Error 1

It does build an executable, but my computer says it can't run it. I tried searching the internet, and found gcc bug reports including this error. There is probably something stupid that I am doing to get this error. How do I fix this error, and what does it mean?

EDIT: Full output:

make
gcc -Wall -g -c ../src/OpenGLDemo.c
gcc ../src/OpenGLDemo.c -o "OpenGL Demo" -L./libs -lglfw3
C:/Windows/SysWOW64/opengl32.dll C:/Windows/SysWOW64/glu32.dll
cygwin warning:
  MS-DOS style path detected: C:/Windows/SysWOW64/opengl32.dll
  Preferred POSIX equivalent is: /cygdrive/c/Windows/SysWOW64/opengl32.dll
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
collect2: error: ld terminated with signal 11 [Segmentation fault], core dumped
makefile:11: recipe for target 'exe' failed
make: *** [exe] Error 1

Solution

  • It means that the ld tool or one of its dependencies has a bug which results in an invalid memory access (segmentation fault) on which the operating system kills the process with SIGSEGV (signal 11). It should not crash regardless of your build setup.

    You should probably file a bug report for ld with your Linux distribution vendor or directly to the vendor of the ld tool (usually GNU in case your ld tool is from the GNU binutils).