undefined reference to `__stack_chk_fail'

為{幸葍}努か 提交于 2019-11-27 08:50:01

libgurobi_c++.a was compiled with -fno-stack-protector (obviously).

A few things come to mind:

  1. add -fno-stack-protector when linking. This will make sure that libssp gets linked.
  2. Manually link -lssp
  3. Make your dummy version of __stack_chk_fail(void) in it's own object file and and add this .o file to your linker command AFTER libgurobi_c++.a. GCC/G++ resolves symbols from left to right during linking so despite your code having the function defined, a copy of an object containing the __stack_chk_fail symbol needs to be on the linker line to the right of libgurobi_c++.a.

https://wiki.ubuntu.com/ToolChain/CompilerFlags

says:

"Usually this is a result of calling ld instead of gcc during a build to perform linking"

This is what I encountered when modified the Makefile of libjpeg manually. Use gcc instead of ld solved the problem.

In gentoo I had the same problem and i resolved creating 2 files. The first contain the option to be parsed by emerge and passed to gcc:

/etc/portage/env/nostackprotector.conf
CFLAGS="-fno-stack-protector -O2"

And the second tells which package should use this settings:

/etc/portage/package.env/nostackprotector
x11-libs/vte nostackprotector.conf
sys-libs/glibc nostackprotector.conf
www-client/chromium nostackprotector.conf
app-admin/sudo nostackprotector.conf
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!