Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

c++ - program linking fails when using custom built gcc

I'm running a fedora 21 distribution, in which the default gcc is 4.9. I have a custom built gcc/g++ 4.8 in /usr/local/gcc48 (for instance, cuda requires gcc =< 4.8, and i use update-alternatives to chose this one) I have been compiling a few small programs with this version 4.8 without problem so far.

Now, I have been given a source code which makes uses of vtk libraries and others. If I use default gcc 4.9, cmake and make work fine. However, when using gcc48, I get:

/usr/lib64/vtk/libvtkCommonDataModel.so.1: référence indéfinie vers ? std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20 ?
/lib64/libicuuc.so.52: référence indéfinie vers ? __cxa_throw_bad_array_new_length@CXXABI_1.3.8 ?
collect2: erreur: ld a retourné 1 code d'état d'exécution
CMakeFiles/main.dir/build.make:365: recipe for target '../bin/main'   failed
make[2]: *** [../bin/main] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2

I understand that is it a linker error, I tried to point LD_LIBRARY_PATH=/usr/local/gcc48/lib or LD_LIBRARY_PATH=/usr/local/gcc48/lib64, but i'm stuck.

What is the problem here ?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

__cxa_throw_bad_array_new_length was added in GCC 4.9. That's what the @CXXABI_1.3.8 version suffix means. You can look up those version codes here: https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html

This error means that you are trying to link an object file /usr/lib64/vtk/libvtkCommonDataModel.so.1 compiled by GCC 4.9 or later with libstdc++.so or libsupc++.so from GCC 4.8 or earlier. Either rebuild libvtkCommonDataModel.so with GCC 4.8, or link against the correct libstdc++.so.

Edit: Actually, if you want to compile with a newer version of GCC but run with an older libstdc++.so, that can be done.

  1. Compile with -D_GLIBCXX_USE_CXX11_ABI=0 if you want to compile with GCC 5+ and run with libstdc++.so from older GCC. See https://bugzilla.mozilla.org/show_bug.cgi?id=1153109 and Using dual ABI in the libstdc++ manual.

  2. Link against stdc++compat.cpp containing back-compat hacks from Mozilla. You can also take a look at my modified version which doesn't depend on any Mozilla headers, but it's slightly out of date. In particular, this defines a stub __cxa_throw_bad_array_new_length.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...