未定义的引用`__stack_chk_fail' [英] undefined reference to `__stack_chk_fail'
本文介绍了未定义的引用`__stack_chk_fail'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编译C ++代码时出现此错误:
未定义引用`__stack_chk_fail'
已尝试的选项:
- 添加-fno- stack-protector在编译时 - 没有工作,错误仍然存在
- 在我的代码中添加了一个虚拟实现void __stack_chk_fail(void)。仍然遇到同样的错误。
详细错误:
/ u / ac / alanger / gurobi / gurobi400 / linux64 / lib / libgurobi_c ++ a(Env.o)(.text + 0x1034):在函数`GRBEnv :: getPar / u / ac /在函数`GRBEnv :: getParamInfo(GRB_StringParam,std :: basic_string< char,std :: char_traits< char>,std:char_traits< char>,...)中,使用下面的函数:gurobi / gurobi400 / linux64 / lib / libgurobi_c ++。 :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& std :: allocator< char>>&)':
:**未定义的引用`__stack_chk_fail'**
早些时候,我得到了10个这样的错误。发现我使用的预编译库的
gcc
与gcc
版本之间存在版本不匹配我用来编译代码。更新了gcc
,现在我只得到其中两个错误。
有任何帮助吗?
解决方案libgurobi_c ++。a是用-fno-stack-protector编译的(很明显)。
有几件事情想起来了:
- 添加 -fno-stack-protector 链接。
- 手动链接 -lssp
- 将您的虚拟版本__stack_chk_fail )在它自己的对象文件中,并将此.o文件添加到链接器命令 AFTER libgurobi_c ++。 GCC / G ++在链接期间从左到右解析符号,尽管你的代码具有定义的函数,包含__stack_chk_fail符号的对象的副本需要在libgurobi_c ++右边的链接行上。a。
Getting this error while compiling C++ code:
undefined reference to `__stack_chk_fail'
Options already tried:
- added -fno-stack-protector while compiling - did not work, error persists
- added a dummy implementation of void __stack_chk_fail(void) in my code. Still getting the same error.
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 thegcc
version I was using to compile the code. Updatedgcc
and now I am getting only 2 of these errors.Any help, please?
解决方案libgurobi_c++.a was compiled with -fno-stack-protector (obviously).
A few things come to mind:
- add -fno-stack-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.
这篇关于未定义的引用`__stack_chk_fail'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文