链接器无法找到__assert_fail

时间:2013-08-10 19:17:41

标签: c++ linker

我正在尝试构建一个使用boost的库,当库编译好的时候,它会遇到一个我不理解的奇怪的链接器错误。我建立并安装了Boost 1.54(也试过1.52),这很好。

它声称无法找到__assert_fail,我认为它是标准库的一部分。我尝试用64位构建所有东西。我在Fedora 16上使用gcc 4.6.3

有什么想法吗?

make  all-am
make[1]: Entering directory `/data/adrian/code/ext/mapper/cmappertools'
/bin/sh ./libtool  --tag=CXX   --mode=link g++  -g -O2    -o libcmappertools.la -rpath /usr/local/lib/python2.7/site-packages cmappertools.lo  
libtool: link: g++  -fPIC -DPIC -shared -nostdlib /usr/lib/gcc/x86_64-redhat-linux/4.6.3/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.6.3/crtbeginS.o  .libs/cmappertools.o   -L/usr/lib/gcc/x86_64-redhat-linux/4.6.3 -L/usr/lib/gcc/x86_64-redhat-linux/4.6.3/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.6.3/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/x86_64-redhat-linux/4.6.3/crtendS.o /usr/lib/gcc/x86_64-redhat-linux/4.6.3/../../../../lib64/crtn.o  -O2   -Wl,-soname -Wl,libcmappertools.so.0 -o .libs/libcmappertools.so.0.0.0
.libs/cmappertools.o: In function `condition_variable':
/usr/local/include/boost/thread/pthread/condition_variable_fwd.hpp:69: undefined reference to `__assert_fail'
/usr/local/include/boost/thread/pthread/condition_variable_fwd.hpp:69: undefined reference to `__assert_fail'
.libs/cmappertools.o: In function `~mutex':
/usr/local/include/boost/thread/pthread/mutex.hpp:108: undefined reference to `__assert_fail'
.libs/cmappertools.o: In function `condition_variable':
/usr/local/include/boost/thread/pthread/condition_variable_fwd.hpp:69: undefined reference to `__assert_fail'
.libs/cmappertools.o: In function `~mutex':
/usr/local/include/boost/thread/pthread/mutex.hpp:108: undefined reference to `__assert_fail'
.libs/cmappertools.o:/usr/local/include/boost/smart_ptr/shared_array.hpp:194: more undefined references to `__assert_fail' follow
/usr/local/bin/ld: .libs/libcmappertools.so.0.0.0: hidden symbol `__assert_fail' isn't defined
/usr/local/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
make[1]: *** [libcmappertools.la] Error 1
make[1]: Leaving directory `/data/adrian/code/ext/mapper/cmappertools'
make: *** [all] Error 2

2 个答案:

答案 0 :(得分:1)

several years later, on different Fedora (29), later version of boost, gcc, etc.etc. I ran into the same problem. Led more by intuition than understanding I got rid of gcc visibility pragmas (i.e. I commented out all the: #pragma GCC visibility push({whatever}) ... #pragma GCC visibility pop) and that did the trick - it compiled, linked and run successfully.

答案 1 :(得分:0)

正如塔尼(Tarni)所述,

hidden symbol `__assert_fail' isn't defined

确实是由#pragma GCC visibility push(hidden)

引起的

但是,如果您绝对需要隐藏一些调用assert宏的函数,则应在隐藏任何符号之前将其包括在内,例如


// Wrong place to hide
// #pragma GCC visibility push(hidden) 

#include <assert.h>

// Right place to hide
#pragma GCC visibility push(hidden) 

void fatal_debug(int foo, int bar){
    assert(foo == bar);
}


#pragma GCC visibility pop