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

不打扰是莪最后的温柔 提交于 2020-07-29 12:12:04

问题


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

回答1:


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).




回答2:


I came across exactly the same error.

I'm developing on Windows and Linux at the same time and use Filezilla to transfer my files. The code built previously on Windows with Cygwin, but wouldn't after downloading files from my Linux host.

The process was build on Windows ==> upload to Linux and build ==> make a few changes ==> download to Windows and build ==> get error.

Then it dawned on me I had transferred over the Linux object files with the source, so I erased all the .o files and the build went fine.

I can't say if this was @Zaerospi's problem or not, but it seems to have been the source of my error.

Anyone else with the same error may want to try erasing their object files and rebuilding.



来源:https://stackoverflow.com/questions/25371372/collect2-error-ld-terminated-with-signal-11-segmentation-fault-core-dumped

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!