0

I am using TDM-GCC-64 for the project. Here is the minimal source code (the full source includes code for Python module initialization):

// minimal.cpp
#include <Python.h>

extern "C"
{

static PyObject * f() {
    PyObject * tuple = PyTuple_New(2);
    PyTuple_SetItem(tuple, 0, PyLong_FromLong(0L));
    PyTuple_SetItem(tuple, 1, PyFloat_FromDouble(0.));
    return tuple;
}

}

int main()
{
  f();
  return 0;
}

And the Makefile (the original rule compiles the code into an .so file):

ANACONDA_PKGS = C:/Anaconda3/pkgs
PY_INCLUDE = -I$(ANACONDA_PKGS)/python-3.5.2-0/include
PY_LINK = -L$(ANACONDA_PKGS)/libpython-2.0-py35_0/libs -lpython35.dll
CXXFLAGS = -fPIC -fopenmp -O3 -std=c++11 $(PY_INCLUDE) $(PY_LINK) -Wall
CC = g++

test: minimal.o
    $(CC) $(CXXFLAGS) -o minimal.exe minimal.o

minimal: minimal.cpp
    $(CC) $(CXXFLAGS) -c minimal.cpp

Then running make test gives:

minimal.o:minimal.cpp:(.text.startup+0x12): undefined reference to `__imp_PyTuple_New'
minimal.o:minimal.cpp:(.text.startup+0x1d): undefined reference to `__imp_PyLong_FromLong'
minimal.o:minimal.cpp:(.text.startup+0x2c): undefined reference to `__imp_PyTuple_SetItem'
minimal.o:minimal.cpp:(.text.startup+0x38): undefined reference to `__imp_PyFloat_FromDouble'
collect2.exe: error: ld returned 1 exit status
Makefile:29: recipe for target 'test' failed
make: *** [test] Error 1

I also checked libpython35.dll.a by nm, and it looks like the functions are there. For example, the following text can be found in the output of nm:

deuhs00780.o:
0000000000000000 b .bss
0000000000000000 d .data
0000000000000000 i .idata$4
0000000000000000 i .idata$5
0000000000000000 i .idata$6
0000000000000000 i .idata$7
0000000000000000 t .text
0000000000000000 I __imp_PyTuple_New
                 U _head_C__Users_ray_mc_x64_3_5_Library_home_ray_mc_x64_3_5_conda_bld_libpython_1476533413999__b_env_libs_libpython35_dll_a
0000000000000000 T PyTuple_New

So where is the problem? Thanks.

Ziyuan
  • 4,215
  • 6
  • 48
  • 77
  • There are both 32 and 64-bit versions of the Python interpreter (both of which will run on a 64-bit OS). Could you be compiling 64-bit code and trying to link it with 32-bit libraries? – martineau Dec 04 '16 at 16:52
  • @martineau `conda info libpython` shows the package is for Win64 – Ziyuan Dec 04 '16 at 18:20
  • My point was that there's both a 32-bit and a 64-bit version of Python that will both _run_ on windows x64, and the 32-bit version is very commonly used since many extension only come pre-built in that flavor. You need to determine which version of Python you have and make sure you're compiling and linking your add-on's code appropriately. – martineau Dec 04 '16 at 19:21
  • @martineau No I only install the 64-bit version of Python (Anaconda) – Ziyuan Dec 05 '16 at 08:51

0 Answers0