C++ Python 3.3带有静态链接的未定义引用

C++ Python 3.3带有静态链接的未定义引用,c++,python,g++,static-linking,python-3.3,C++,Python,G++,Static Linking,Python 3.3,操作系统:Ubuntu 12.04 x86_64 我已经从源代码处编译了libpython3.3m.a以及相关的头文件。我编写了以下Makefile(具体地说,看看我的CFLAGS变量,其中包括-lpython3.3m) 我编写了以下.cpp源文件 #include <Python.h> int main(int argc, char** argv) { Py_SetProgramName((wchar_t*)argv[0]); /* optional but recomme

操作系统:Ubuntu 12.04 x86_64

我已经从源代码处编译了libpython3.3m.a以及相关的头文件。我编写了以下Makefile(具体地说,看看我的CFLAGS变量,其中包括-lpython3.3m)

我编写了以下.cpp源文件

#include <Python.h>

int main(int argc, char** argv)
{
  Py_SetProgramName((wchar_t*)argv[0]);  /* optional but recommended */
  Py_Initialize();
  PyRun_SimpleString("from time import time,ctime\n"
                     "print 'Today is',ctime(time())\n");
  Py_Finalize();
  return 0;
}
根据我对g++的'-l'参数的理解,它正在查找libpython3.3m.a,因为否则它会告诉我它无法找到库并退出

那么,如果它正在查找库,为什么不定义这些函数呢

附加说明

使用--prefix和altinstall构建Python,将其安装到一个新目录(我在makefile中将LIBROOT指向的目录)

我已确认LibPython330.a的单位为美元(LIBDIR)

正在使用nm检查Py_SetProgramName

uberblah@uberblah-N80Vm:~/lib/cpp/lib$ nm libpython3.3m.a | grep Py_SetProgramName
                 U Py_SetProgramName
0000000000001c00 T Py_SetProgramName
                 U Py_SetProgramName
正在详细运行Make

    ...
    Finished prerequisites of target file `python'.
  Must remake target `python'.
g++ -I/home/uberblah/lib/cpp/include/python3.3m -L/home/uberblah/lib/cpp/lib -lpython3.3m -o python python.cpp
Putting child 0x00a585b0 (python) PID 16811 on the chain.
Live child 0x00a585b0 (python) PID 16811 
/tmp/cc2dom1S.o: In function `main':
python.cpp:(.text+0x1a): undefined reference to `Py_SetProgramName'
python.cpp:(.text+0x1f): undefined reference to `Py_Initialize'
python.cpp:(.text+0x2e): undefined reference to `PyRun_SimpleStringFlags'
python.cpp:(.text+0x33): undefined reference to `Py_Finalize'
collect2: ld returned 1 exit status
Reaping losing child 0x00a585b0 PID 16811 
make: *** [python] Error 1
Removing child 0x00a585b0 PID 16811 from chain.

如果我将编译拆分为一个对象阶段,然后再拆分为一个二进制阶段,则二进制阶段将失败,并显示与最初提到的相同的错误消息。

找到了解决方案:Python实际安装了自己的解决方案。这篇文章中谈到了这一点(我知道我的标题没有丢失,但我很傻,试图自己把它连接起来,想“哦,这正是任何人都需要做的事情,才能让Python在我的平台上工作”)


找到了解决方案:Python实际安装了自己的解决方案。这篇文章中谈到了这一点(我知道我的标题没有丢失,但我很傻,试图自己把它连接起来,想“哦,这正是任何人都需要做的事情,才能让Python在我的平台上工作”)


您的操作系统和寻址体系结构是什么?Ubuntu 12.04 x86\u 64。我使用--prefix和make altinstall构建了Python。回答了您问题的第二部分,在原始postRun
nm libpython3.3m.a
中添加了信息。这些符号就在那里?编辑后的文章结尾回答了nm的问题:你的操作系统和寻址体系结构是什么?Ubuntu 12.04 x86_64。我使用--prefix和make altinstall构建了Python。回答了您问题的第二部分,在原始postRun
nm libpython3.3m.a
中添加了信息。这些符号在哪里?请在文章末尾编辑以回答nm问题
uberblah@uberblah-N80Vm:~/lib/cpp/lib$ nm libpython3.3m.a | grep Py_SetProgramName
                 U Py_SetProgramName
0000000000001c00 T Py_SetProgramName
                 U Py_SetProgramName
    ...
    Finished prerequisites of target file `python'.
  Must remake target `python'.
g++ -I/home/uberblah/lib/cpp/include/python3.3m -L/home/uberblah/lib/cpp/lib -lpython3.3m -o python python.cpp
Putting child 0x00a585b0 (python) PID 16811 on the chain.
Live child 0x00a585b0 (python) PID 16811 
/tmp/cc2dom1S.o: In function `main':
python.cpp:(.text+0x1a): undefined reference to `Py_SetProgramName'
python.cpp:(.text+0x1f): undefined reference to `Py_Initialize'
python.cpp:(.text+0x2e): undefined reference to `PyRun_SimpleStringFlags'
python.cpp:(.text+0x33): undefined reference to `Py_Finalize'
collect2: ld returned 1 exit status
Reaping losing child 0x00a585b0 PID 16811 
make: *** [python] Error 1
Removing child 0x00a585b0 PID 16811 from chain.