python - pyenv环境下如何搭建gdb

标签 python build gdb cython pyenv

我正在尝试使用 pyenv 安装的 python 2.7.12 构建 gdb。 Python 安装命令是

pyenv install 2.7.12 -k

然后我执行如下命令来构建 gdb。

wget ftp://sourceware.org/pub/gdb/releases/gdb-8.1.tar.gz
tar xvf gdb-8.1.tar.gz
cd gdb-8.1
./configure  --with-python=$(pyenv which python) --prefix=/usr/local CFLAGS="-g -O2 -Wno-string-plus-int"
make

但它失败了,我得到了这些错误。

configure: WARNING: MPFR is missing or unusable; some features may be unavailable.
checking whether to use python... /home/useraccount/.pyenv/versions/2.7.12/bin/python
checking for python2.7... no
configure: error: no usable python found at /home/useraccount/.pyenv/versions/2.7.12/bin/python
Makefile:9096: recipe for target 'configure-gdb' failed
make[1]: *** [configure-gdb] Error 1
make[1]: Leaving directory '/tmp/tmp.GE0OV8nAxG/gdb-8.1'
Makefile:849: recipe for target 'all' failed
make: *** [all] Error 2

当我将 gdb 链接到系统 python 时,构建命令起作用。

./configure  --with-python=/usr/bin/python --prefix=/usr/local CFLAGS="-g -O2 -Wno-string-plus-int"
make

我想使用 cygdb 来调试我的 cython 程序,但因此,我无法正常运行 cygdb。

我们将不胜感激任何帮助。

环境

  • Ubuntu 16.04 x64

gdb/config.log

configure:10391: gcc -o conftest -g -O2 -Wno-string-plus-int  -I/home/useraccount/.pyenv/versions/2.7.12/include/python2.7 -I/home/useraccount/.pyenv/versions/2.7.12/include/python2.7 -static-libstdc++ -static-libgcc  conftest.c -ldl -lncurses -lm -ldl  -L/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config -lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic >&5
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(posixmodule.o): In function `posix_tmpnam':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/./Modules/posixmodule.c:7631: warning: the use of `tmpnam_r' is dangerous, better use `mkstemp'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(posixmodule.o): In function `posix_tempnam':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the use of `tempnam' is dangerous, better use `mkstemp'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(signalmodule.o): In function `timeval_from_double':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/./Modules/signalmodule.c:112: undefined reference to `floor'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/./Modules/signalmodule.c:113: undefined reference to `fmod'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/./Modules/signalmodule.c:112: undefined reference to `floor'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/./Modules/signalmodule.c:113: undefined reference to `fmod'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(complexobject.o): In function `_Py_c_abs':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:214: undefined reference to `hypot'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(complexobject.o): In function `complex_remainder':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:616: undefined reference to `floor'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(complexobject.o): In function `complex_divmod':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:642: undefined reference to `floor'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(complexobject.o): In function `_Py_c_pow':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:143: undefined reference to `hypot'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:144: undefined reference to `pow'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:145: undefined reference to `atan2'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:147: undefined reference to `sincos'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:148: undefined reference to `exp'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:149: undefined reference to `log'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:143: undefined reference to `hypot'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:144: undefined reference to `pow'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:145: undefined reference to `atan2'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:145: undefined reference to `sincos'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(complexobject.o): In function `_Py_c_abs':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/complexobject.c:214: undefined reference to `hypot'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(floatobject.o): In function `float_is_integer':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:996: undefined reference to `floor'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(floatobject.o): In function `float_divmod':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:760: undefined reference to `fmod'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:786: undefined reference to `floor'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:760: undefined reference to `fmod'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(floatobject.o): In function `float_rem':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:728: undefined reference to `fmod'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:728: undefined reference to `fmod'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(floatobject.o): In function `float_divmod':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:760: undefined reference to `fmod'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:786: undefined reference to `floor'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:760: undefined reference to `fmod'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(floatobject.o): In function `float_as_integer_ratio':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:1748: undefined reference to `floor'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(floatobject.o): In function `float_pow':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:863: undefined reference to `fmod'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:873: undefined reference to `fmod'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:922: undefined reference to `pow'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:888: undefined reference to `floor'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:898: undefined reference to `fmod'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(floatobject.o): In function `_Py_double_round':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:1103: undefined reference to `round'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:1142: undefined reference to `floor'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/floatobject.c:1156: undefined reference to `fmod'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(longobject.o): In function `PyLong_FromString':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Objects/longobject.c:1869: undefined reference to `log'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(dynload_shlib.o): In function `_PyImport_GetDynLoadFunc':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/dynload_shlib.c:94: undefined reference to `dlsym'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/dynload_shlib.c:130: undefined reference to `dlopen'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/dynload_shlib.c:141: undefined reference to `dlsym'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/dynload_shlib.c:133: undefined reference to `dlerror'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `PyThread_acquire_lock':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:324: undefined reference to `sem_wait'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `PyThread_release_lock':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:350: undefined reference to `sem_post'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `PyThread_start_new_thread':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:194: undefined reference to `pthread_create'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:210: undefined reference to `pthread_detach'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:184: undefined reference to `pthread_attr_setstacksize'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `PyThread_allocate_lock':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:269: undefined reference to `sem_init'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `PyThread_free_lock':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:294: undefined reference to `sem_destroy'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `PyThread_acquire_lock':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:326: undefined reference to `sem_trywait'
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:324: undefined reference to `sem_wait'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `PyThread_release_lock':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:350: undefined reference to `sem_post'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `_pythread_pthread_set_stacksize':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:497: undefined reference to `pthread_attr_setstacksize'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `PyThread_allocate_lock':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:269: undefined reference to `sem_init'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `PyThread_acquire_lock':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:324: undefined reference to `sem_wait'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `PyThread_release_lock':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:350: undefined reference to `sem_post'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `PyThread_acquire_lock':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:324: undefined reference to `sem_wait'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `PyThread_release_lock':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:350: undefined reference to `sem_post'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(thread.o): In function `PyThread_allocate_lock':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/Python/thread_pthread.h:269: undefined reference to `sem_init'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(posixmodule.o): In function `posix_forkpty':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/./Modules/posixmodule.c:4012: undefined reference to `forkpty'
/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config/libpython2.7.a(posixmodule.o): In function `posix_openpty':
/home/useraccount/.pyenv/sources/2.7.12/Python-2.7.12/./Modules/posixmodule.c:3952: undefined reference to `openpty'
collect2: error: ld returned 1 exit status

最佳答案

错误似乎出现在 configure 脚本中。特别是,这个命令:

gcc -o conftest -g ... conftest.c -ldl -lncurses -lm -ldl  \
  -L/home/useraccount/.pyenv/versions/2.7.12/lib/python2.7/config \
  -lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic

是倒退的(libpython2.7 依赖于 libpthread,因此在命令行中应该在它之前)。

我从当前的 git head 检查了我的 config.log,它有同样的问题。

进一步看,GDB 在 configureing 时运行 python python/python-config.py --ldflags

应用这个补丁:

diff --git a/gdb/python/python-config.py b/gdb/python/python-config.py
index c2b2969c39..0d38ed50c0 100644
--- a/gdb/python/python-config.py
+++ b/gdb/python/python-config.py
@@ -58,12 +58,11 @@ for opt in opt_flags:
         print (to_unix_path(' '.join(flags)))

     elif opt in ('--libs', '--ldflags'):
-        libs = []
+        libs = ['-lpython'+pyver + abiflags]
         if getvar('LIBS') is not None:
             libs.extend(getvar('LIBS').split())
         if getvar('SYSLIBS') is not None:
             libs.extend(getvar('SYSLIBS').split())
-        libs.append('-lpython'+pyver + abiflags)
         # add the prefix/lib/pythonX.Y/config dir, but only if there is no
         # shared library in prefix/lib/.
         if opt == '--ldflags':

并重新运行 configure 应该会为您解决此问题。

关于python - pyenv环境下如何搭建gdb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49850815/

相关文章:

c++ - gdb:tstart 错误 "You can' 的含义 t 当你的目标是 `exec' 时执行此操作“

python - 错误: The truth value of an array with more than one element is ambiguous

python - 如何使用 Python 中的面向对象编程来构建机器学习项目?

python - 从文件中读取不同格式的日期并对它们进行排序

flutter - 无法建立Flutter APK以发布

xcode - 提交到App Store时为"the CodeResources file must be a symbolic link to _CodeSignature..."

c - 调试msp430时在GDB中打印变量值

使用 Django 的 Javascript?

android - 预览未在Android Studio 3.1.4中显示

c - 为什么从 int 的地址读回不给我返回 int 的正确值(C 和 gdb)