Undefined Reference to '_Stack_Chk_Fail'

undefined reference to `__stack_chk_fail'

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

A few things come to mind:

  1. add -fstack-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.

undefined reference to '__stack_chk_fail_local'

__stack_chk_fail_local is a function frim glibc which basically call stack_chk_fail.

/* On some architectures, this helps needless PIC pointer setup
that would be needed just for the __stack_chk_fail call. */

void __attribute__ ((noreturn)) attribute_hidden
__stack_chk_fail_local (void)
{
__stack_chk_fail ();
}

In my Installation, this function is part of libc_nonshared.a which is a library which contains some functions not present in the shared library.

You can see these information by reading libc.so, mine can be found at /usr/lib/x86_64-linux-gnu/libc.so.

/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /lib/x86_64-linux-gnu/libc.so.6 /usr/lib/x86_64-linux-gnu/libc_nonshared.a AS_NEEDED ( /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ) )

The idea is to compile a simple test:

int main()
{
__stack_chk_fail_local();
return 0;
}

With the command line gcc -o exec x.c -Wl,-Map,x.map and see if it compile (you will get a warning). If it compiles , the problem is probably coming from your linker script and/or your command lines, otherwise your installation is corrupted or incomplete.

In the second case you need probably to reinstall libc6-dev if you are using Ubuntu for example.

undefined reference to _GLOBAL_OFFSET_TABLE_ (only when generating binaries)

Your toolchain probably defaults to generating position-independent executables (PIE). Try compiling with gcc -fno-pie.

If you want to keep PIE for security reasons, you'll need a more complicated linker script and something that performs the initial relocation (such as a dynamic linker, but simpler constructions are possible as well).

What does this GCC error ... relocation truncated to fit... mean?

You are attempting to link your project in such a way that the target of a relative addressing scheme is further away than can be supported with the 32-bit displacement of the chosen relative addressing mode. This could be because the current project is larger, because it is linking object files in a different order, or because there's an unnecessarily expansive mapping scheme in play.

This question is a perfect example of why it's often productive to do a web search on the generic portion of an error message - you find things like this:

http://www.technovelty.org/code/c/relocation-truncated.html

Which offers some curative suggestions.

R package with Fortran module on Windows? undefined reference to `__stack_chk_fail'

Create a Makevars.win file in your src directory with the following line.

PKG_FCFLAGS="-fno-stack-protector"

Then also change useDynLib(Fpi) in the NAMESPACE to useDynLib(MyPi) as that is what the package name is.

Try and build the package. If the output doesn't show the flag being used, the environmental variable may not currently exist and fail work. Not exactly sure why this would happen. If this is the case, just simply initialize the environmental variable.

Sys.setenv(PKG_FCFLAGS = "")

This gets your package to build on my Windows system.



Related Topics



Leave a reply



Submit