Getting this error while compiling C++ code:
undefined reference to `__stack_chk_fail'
Options already tried:
Detailed Error:
/u/ac/alanger/gurobi/gurobi400/linux64/lib/libgurobi_c++.a(Env.o)(.text+0x1034): In function `GRBEnv::getPar/u/ac/alanger/gurobi/gurobi400/linux64/lib/libgurobi_c++.a(Env.o)(.text+0x1034): In function `GRBEnv::getParamInfo(GRB_StringParam, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
: undefined reference to `__stack_chk_fail'
amInfo(GRB_StringParam, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
: **undefined reference to `__stack_chk_fail'**
Earlier, I was getting 10's of such errors. Found out that there was a version mismatch between the gcc
of the pre-compiled libraries I am using and the gcc
version I was using to compile the code. Updated gcc
and now I am getting only 2 of these errors.
Any help, please?
__stack_chk_fail , a callback function that is invoked when a stack buffer overflow is detected. This function shall abort the function that called it with a message that a stack buffer overflow has been detected, and then halt the program via exit , abort , or a custom panic handler.
-fno-stack-protector disables stack protection. -fstack-protector enables stack protection for vulnerable functions that contain: A character array larger than 8 bytes. An 8-bit integer array larger than 8 bytes.
libgurobi_c++.a was compiled with -fno-stack-protector (obviously).
A few things come to mind:
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
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With