undefined reference to `__stack_chk_fail'
Solution 1:
libgurobi_c++.a was compiled with -fno-stack-protector (obviously).
A few things come to mind:
- add -fstack-protector when linking. This will make sure that libssp gets linked.
- Manually link -lssp
- 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.
Solution 2:
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
Solution 3:
Just had the same issue: c++ code with an implementation of void __stack_chk_fail(void)
showing several undefined reference to __stack_chk_fail
errors when compiling.
My solution was to define __stack_chk_fail(void)
as extern "C"
:
extern "C" {
__stack_chk_fail(void)
{
...
}
}
This suppressed the compilation error :)
Hope it helps!