解決 version `GLIBC_2.17' not found
阿新 • • 發佈:2019-02-10
導致這個原因是一個在新的環境編譯出來的程式跑在了老的環境裡。然而,往往你沒有許可權去更新系統的glibc和gcc,又不想去重新編譯一個程式,所以這裡提供了一個比較hack的方法。我們以在redhat el6上安裝tensoflow為例。
1) 安裝支援c++11的編譯器。
2)pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.6.0-cp27-none-linux_x86_64.whl
3)TENSORFLOW_DIR=`python -c "import imp; print(imp.find_module('tensorflow')[1])"
for addr in0xDC5EA40xDC5F040xDC5F540xDC5F740xDC5F840xDC5FA4;do printf '\x02'| dd conv=notrunc of=${TENSORFLOW_DIR}/python/_pywrap_tensorflow.so bs=1 seek=$((addr)); done
4) 檢查 即對GLIBC進行了weak.
readelf-V ${TENSORFLOW_DIR}/python/_pywrap_tensorflow.so
5) 接下來做一些符號丟失的彌補
mkdir ~/my_stubs
cd ~/my_stubs
MYSTUBS=~/ my_stubs
printf "#include <time.h>\n#include <string.h>\nvoid* memcpy(void *dest, const void *src, size_t n) {\nreturn memmove(dest, src, n);\n}\nint clock_gettime(clockid_t clk_id, struct timespec *tp) {\nreturn clock_gettime(clk_id, tp);\n}"> mylibc.c
gcc -s -shared -o mylibc.so -fPIC -fno-builtin mylibc.c
6) 繼續彌補
printf "#include <functional>\nvoid std::__throw_bad_function_call(void) {\nexit(1);\n}"> bad_function.cc
gcc -std=c++11-s -shared -o bad_function.so -fPIC -fno-builtin bad_function.cc
git clone https://github.com/gcc-mirror/gcc.git
cd gcc
mkdir my_include
mkdir my_include/ext
cp libstdc++-v3/include/ext/aligned_buffer.h my_include/ext
gcc -I$PWD/my_include -std=c++11-fpermissive -s -shared -o $MYSTUBS/hashtable.so -fPIC -fno-builtin libstdc++-v3/src/c++11/hashtable_c++0x.cc
gcc -std=c++11-fpermissive -s -shared -o $MYSTUBS/chrono.so -fPIC -fno-builtin libstdc++-v3/src/c++11/chrono.cc
gcc -std=c++11-fpermissive -s -shared -o $MYSTUBS/random.so -fPIC -fno-builtin libstdc++-v3/src/c++11/random.cc
gcc -std=c++11-fpermissive -s -shared -o $MYSTUBS/hash_bytes.so -fPIC -fno-builtin ./libstdc++-v3/libsupc++/hash_bytes.cc
7) 執行
LIBSTDCPP=`ldconfig -p | grep libstdc++.so.6| grep 64| cut -d' '-f4`#For 64bit machines
LD_PRELOAD="$MYSTUBS/mylibc.so:$MYSTUBS/random.so:$MYSTUBS/hash_bytes.so:$MYSTUBS/chrono.so:$MYSTUBS/hashtable.so:$MYSTUBS/bad_function.so:$LIBSTDCPP" python ${TENSORFLOW_DIR}/models/image/mnist/convolutional.py
參考來源:
http://stackoverflow.com/questions/33655731/error-while-importing-tensorflow-in-python2-7-in-ubuntu-12-04-glibc-2-17-not-f/34897674#34897674
http://stackoverflow.com/questions/33655731/error-while-importing-tensorflow-in-python2-7-in-ubuntu-12-04-glibc-2-17-not-f/34900471#34900471