I have successfully installed theano on Canopy EPD, windows 7, 64 bit. While importing theano (for testing at first time), I am getting this error. Can anybody help. Thanks.
It is similar to this question:
Installing Theano on EPD (Windows x64)
Exception: Compilation failed (return status=1): C:\Users\HARISH~1\AppData\Local\Temp\ccLHOaX7.o: In function unpack_list_of_ssize_t':. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:58: undefined reference to__imp_PyExc_TypeError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:68: undefined reference to __imp_PyExc_IndexError'. C:\Users\HARISH~1\AppData\Local\Temp\ccLHOaX7.o: In functionCLazyLinker_init':. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:341: undefined reference to __imp_PyCObject_Type'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:362: undefined reference to__imp_PyExc_IndexError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:380: undefined reference to __imp_PyExc_IndexError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:395: undefined reference to__imp_PyExc_IndexError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:399: undefined reference to __imp_PyExc_IndexError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:403: undefined reference to__imp_PyExc_IndexError'. C:\Users\HARISH~1\AppData\Local\Temp\ccLHOaX7.o:C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:407: more undefined references to __imp_PyExc_IndexError' follow. C:\Users\HARISH~1\AppData\Local\Temp\ccLHOaX7.o: In functionCLazyLinker_init':. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:415: undefined reference to __imp_PyExc_TypeError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:430: undefined reference to__imp__Py_NoneStruct'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:436: undefined reference to __imp_PyExc_IndexError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:450: undefined reference to__imp_PyExc_TypeError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:454: undefined reference to __imp__Py_NoneStruct'. C:\Users\HARISH~1\AppData\Local\Temp\ccLHOaX7.o: In functionc_call':. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:555: undefined reference to __imp__Py_NoneStruct'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:555: undefined reference to__imp__Py_NoneStruct'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:555: undefined reference to __imp__Py_NoneStruct'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:556: undefined reference to__imp__Py_NoneStruct'. C:\Users\HARISH~1\AppData\Local\Temp\ccLHOaX7.o:C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:556: more undefined references to __imp__Py_NoneStruct' follow. C:\Users\HARISH~1\AppData\Local\Temp\ccLHOaX7.o: In functionlazy_rec_eval':. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:628: undefined reference to __imp_PyExc_IndexError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:651: undefined reference to__imp_PyExc_TypeError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:659: undefined reference to __imp_PyExc_ValueError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:667: undefined reference to__imp_PyExc_IndexError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:718: undefined reference to __imp__Py_NoneStruct'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:725: undefined reference to__imp_PyExc_TypeError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:731: undefined reference to __imp_PyExc_TypeError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:781: undefined reference to__imp__Py_NoneStruct'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:781: undefined reference to __imp__Py_NoneStruct'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:782: undefined reference to__imp__Py_NoneStruct'. C:\Users\HARISH~1\AppData\Local\Temp\ccLHOaX7.o: In function CLazyLinker_call':. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:817: undefined reference to__imp__Py_NoneStruct'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:817: undefined reference to __imp__Py_NoneStruct'. C:\Users\HARISH~1\AppData\Local\Temp\ccLHOaX7.o:C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:818: more undefined references to__imp__Py_NoneStruct' follow. C:\Users\HARISH~1\AppData\Local\Temp\ccLHOaX7.o: In function CLazyLinker_call':. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:867: undefined reference to__imp_PyExc_AssertionError'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:910: undefined reference to __imp__Py_NoneStruct'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:910: undefined reference to__imp__Py_NoneStruct'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:911: undefined reference to __imp__Py_NoneStruct'. C:\Users\HARISH~1\AppData\Local\Temp\ccLHOaX7.o: In functionCLazyLinker_set_allow_gc':. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:943: undefined reference to __imp_PyBool_Type'. C:/Users/Harish-Chandra/AppData/Local/Theano/compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.9-64/lazylinker_ext/mod.cpp:946: undefined reference to__imp__Py_TrueStruct'. collect2: ld returned 1 exit status.
Since this question wasnt properly closed by the author and it's also relevant to most EPD users, including me when i first started with EPD + theano, i will answer to it.
First, remove any other python environment if possible.
Be sure there is no other conflicting environment path of python, just in case.
1.Install EPD CANOPY
2.Install the MinGW package that is on package installer available on Canopy application
That should be easy to do, you just open the package manager from inside the Canopy application.
3.Install Theano from inside EPD
Before you go spamming
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
in every prompt of command you see, DONT DO IT.
--
Instead, Open Canopy.
In Canopy screen, go to "Tools", and then open "Canopy Command Prompt"
A screen exactly like the CMD from windows will open.
On that screen, execute :
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
Should work fine now.
--
However, dont forget you will need , obviously the Windows SDK , depending on the windows version of course.
You can try installing the last Visual Studio with comes with everything you need.
If you need more info on this, check this related Stackoverflow topic :
Installing theano
Related
I want to use Swig to use my C/C++ "model-controler" application with Python HMI.
I first test python swig simple example on my ubuntu PC and it works like a charm.
Then I tried to do the same on a Win7-64bits with Mingw-64:
"Wrap" by using
swig.exe -python path_to_swig_examples\python\simple\example
in cmd window, it's generate example_wrap.c… Ok
Then compile under mingw terminal (personally I launch by right-click in explorer then Git Bash here)
gcc -c -fPIC -DWIN32 example.c example_wrap.c -I/C/Program\ Files\ \(x86\)/Python36-32/include
generate my objs…Ok
and link
ld -shared example.o example_wrap.o -o _example.dll
and I have many undefined reference
example_wrap.o:example_wrap.c:(.text+0xe3): undefined reference to `strlen'
example_wrap.o:example_wrap.c:(.text+0x1de): undefined reference to `strcmp'
example_wrap.o:example_wrap.c:(.text+0x5ff): undefined reference to `strcmp'
example_wrap.o:example_wrap.c:(.text+0x957): undefined reference to `strlen'
example_wrap.o:example_wrap.c:(.text+0x98f): undefined reference to `strcpy'
example_wrap.o:example_wrap.c:(.text+0x9c8): undefined reference to `strcmp'
example_wrap.o:example_wrap.c:(.text+0xa38): undefined reference to `strlen'
example_wrap.o:example_wrap.c:(.text+0xaaf): undefined reference to `strncpy'
example_wrap.o:example_wrap.c:(.text+0xaf5): undefined reference to `strcmp'
example_wrap.o:example_wrap.c:(.text+0xb11): undefined reference to `memset'
example_wrap.o:example_wrap.c:(.text+0xb57): undefined reference to `__imp_PyUnicode_AsUTF8String'
example_wrap.o:example_wrap.c:(.text+0xb76): undefined reference to `__imp_PyBytes_AsStringAndSize'
example_wrap.o:example_wrap.c:(.text+0xb88): undefined reference to `malloc'
example_wrap.o:example_wrap.c:(.text+0xbaa): undefined reference to `memcpy'
example_wrap.o:example_wrap.c:(.text+0xc15): undefined reference to `__imp_PyUnicode_FromString'
example_wrap.o:example_wrap.c:(.text+0xc69): undefined reference to `__imp_PyExc_MemoryError'
example_wrap.o:example_wrap.c:(.text+0xc7c): undefined reference to `__imp_PyExc_IOError'
example_wrap.o:example_wrap.c:(.text+0xc8f): undefined reference to `__imp_PyExc_RuntimeError'
example_wrap.o:example_wrap.c:(.text+0xca2): undefined reference to `__imp_PyExc_IndexError'
I added link to python36.dll (based on Anaconda3: https://www.continuum.io/downloads) /c/ProgramData/Anaconda3/python36.dll:
ld -shared example.o example_wrap.o /c/ProgramData/Anaconda3/python36.dll -o _example.dll
and python undefined msgs disappeared… but I have still C/C++ functions undefined reference …
…
ld -shared example.o example_wrap.o /c/ProgramData/Anaconda3/python36.dll /c/Windows/System32/msvcr120.dll -o _example.dll
and dll was created !
Thanks for is all the available swig+python+mingw compile information outdated?
… dll was created but doesn't works:
"ModuleNotFoundError: No module named '_example' "
swig no module named _example
then rename dll to pyd…
ImportError: DLL load failed: %1 is not a valid Win32 application
…was because it is python in 32 bits I ran.
Launch anaconda python:
C:\Program Data\Anaconda3\python.exe
Python 3.5.1 |Anaconda 4.4.0 (64-bit)…
>>> import example
>>> example.gcd(42,36)
6
>>> example.cvar.Foo
3.0
finally, it works… after much time spent !
Versions:
Windows 7 sp1
Swig 3.0.12
MingW-64
Anaconda3 4.4.0
gcc 6.2.0 / ld 2.25
Try to embed python3.6 in C++ on Win10 64bit system.
Python is installed by python-3.6.1-amd64.exe.
The CMakeList.txt is showing below
cmake_minimum_required(VERSION 3.8)
project(EmbedPython)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
add_executable(EmbedPython ${SOURCE_FILES} ${PYTHON_INCLUDE_DIRS})
target_link_libraries(EmbedPython ${PYTHON_LIBRARIES})
And CMake found the Python package.
PYTHON_INCLUDE_DIR C:/Program Files (x86)/Python36/include
PYTHON_LIBRARY C:/Program Files (x86)/Python36/libs/python36.lib
Find a comment on github it's talking about the API problem.
# used to embed python script
find_package(PythonLibs 2.7 REQUIRED) # this has to be 2.7 because the 3.0 API requires argv to be wchar_t** rather than the default char**
include_directories(${PYTHON_INCLUDE_DIRS})
target_link_libraries( assignment ${PYTHON_LIBRARIES})
The errors below is what I'm facing.
[ 50%] Building CXX object CMakeFiles/EmbedPython.dir/main.cpp.obj
[100%] Linking CXX executable EmbedPython.exe
CMakeFiles\EmbedPython.dir/objects.a(main.cpp.obj): In function `main':
D:/Projects/EmbedPython/main.cpp:16: undefined reference to `_imp__Py_Initialize'
D:/Projects/EmbedPython/main.cpp:17: undefined reference to `_imp__PyUnicode_DecodeFSDefault'
D:/Projects/EmbedPython/main.cpp:20: undefined reference to `_imp__PyImport_Import'
D:/Projects/EmbedPython/main.cpp:24: undefined reference to `_imp__PyObject_GetAttrString'
D:/Projects/EmbedPython/main.cpp:27: undefined reference to `_imp__PyCallable_Check'
D:/Projects/EmbedPython/main.cpp:28: undefined reference to `_imp__PyTuple_New'
D:/Projects/EmbedPython/main.cpp:30: undefined reference to `_imp__PyLong_FromLong'
D:/Projects/EmbedPython/main.cpp:38: undefined reference to `_imp__PyTuple_SetItem'
D:/Projects/EmbedPython/main.cpp:40: undefined reference to `_imp__PyObject_CallObject'
D:/Projects/EmbedPython/main.cpp:43: undefined reference to `_imp__PyLong_AsLong'
D:/Projects/EmbedPython/main.cpp:49: undefined reference to `_imp__PyErr_Print'
D:/Projects/EmbedPython/main.cpp:55: undefined reference to `_imp__PyErr_Occurred'
D:/Projects/EmbedPython/main.cpp:56: undefined reference to `_imp__PyErr_Print'
D:/Projects/EmbedPython/main.cpp:63: undefined reference to `_imp__PyErr_Print'
D:/Projects/EmbedPython/main.cpp:67: undefined reference to `_imp__Py_FinalizeEx'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [EmbedPython.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/EmbedPython.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/EmbedPython.dir/rule] Error 2
mingw32-make.exe: *** [EmbedPython] Error 2
CMakeFiles\EmbedPython.dir\build.make:96: recipe for target 'EmbedPython.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/EmbedPython.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/EmbedPython.dir/rule' failed
Makefile:117: recipe for target 'EmbedPython' failed
Not sure what to do to make the project run.Any help would be appreciated.
EDIT:
the result from make VERBOSE=1
D:\Projects\EmbedPython\cmake-build-debug>make VERBOSE=1
"C:\Program Files\JetBrains\CLion 172.2273.4\bin\cmake\bin\cmake.exe" -HD:\Projects\EmbedPython -BD:\Projects\EmbedPython\cmake-build-debug --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\JetBrains\CLion 172.2273.4\bin\cmake\bin\cmake.exe" -E cmake_progress_start D:\Projects\EmbedPython\cmake-build-debug\CMakeFiles D:\Projects\EmbedPython\cmake-build-debug\CMakeFiles\progress.marks
make -f CMakeFiles\Makefile2 all
make[1]: Entering directory 'D:/Projects/EmbedPython/cmake-build-debug'
make -f CMakeFiles\EmbedPython.dir\build.make CMakeFiles/EmbedPython.dir/depend
make[2]: Entering directory 'D:/Projects/EmbedPython/cmake-build-debug'
"C:\Program Files\JetBrains\CLion 172.2273.4\bin\cmake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" D:\Projects\EmbedPython D:\Projects\EmbedPython D:\Projects\EmbedPython\cmake-build-debug D:\Projects\EmbedPython\cmake-build-debug D:\Projects\EmbedPython\cmake-build-debug\CMakeFiles\EmbedPython.dir\DependInfo.cmake --color=
make[2]: Leaving directory 'D:/Projects/EmbedPython/cmake-build-debug'
make -f CMakeFiles\EmbedPython.dir\build.make CMakeFiles/EmbedPython.dir/build
make[2]: Entering directory 'D:/Projects/EmbedPython/cmake-build-debug'
[ 50%] Linking CXX executable EmbedPython.exe
"C:\Program Files\JetBrains\CLion 172.2273.4\bin\cmake\bin\cmake.exe" -E cmake_link_script CMakeFiles\EmbedPython.dir\link.txt --verbose=1
"C:\Program Files\JetBrains\CLion 172.2273.4\bin\cmake\bin\cmake.exe" -E remove -f CMakeFiles\EmbedPython.dir/objects.a
C:\PROGRA~2\MINGW-~1\I686-6~1.0-P\mingw32\bin\ar.exe cr CMakeFiles\EmbedPython.dir/objects.a #CMakeFiles\EmbedPython.dir\objects1.rsp
C:\PROGRA~2\MINGW-~1\I686-6~1.0-P\mingw32\bin\G__~1.EXE -g -Wl,--whole-archive CMakeFiles\EmbedPython.dir/objects.a -Wl,--no-whole-archive -o EmbedPython.exe -Wl,--out-implib,libEmbedPython.dll.a -Wl,--major-image-version,0,--minor-image-version,0 #CMakeFiles\EmbedPython.dir\linklibs.rsp
CMakeFiles\EmbedPython.dir/objects.a(main.cpp.obj): In function `main':
D:/Projects/EmbedPython/main.cpp:16: undefined reference to `_imp__Py_Initialize'
D:/Projects/EmbedPython/main.cpp:17: undefined reference to `_imp__PyUnicode_DecodeFSDefault'
D:/Projects/EmbedPython/main.cpp:20: undefined reference to `_imp__PyImport_Import'
D:/Projects/EmbedPython/main.cpp:24: undefined reference to `_imp__PyObject_GetAttrString'
D:/Projects/EmbedPython/main.cpp:27: undefined reference to `_imp__PyCallable_Check'
D:/Projects/EmbedPython/main.cpp:28: undefined reference to `_imp__PyTuple_New'
D:/Projects/EmbedPython/main.cpp:30: undefined reference to `_imp__PyLong_FromLong'
D:/Projects/EmbedPython/main.cpp:38: undefined reference to `_imp__PyTuple_SetItem'
D:/Projects/EmbedPython/main.cpp:40: undefined reference to `_imp__PyObject_CallObject'
D:/Projects/EmbedPython/main.cpp:43: undefined reference to `_imp__PyLong_AsLong'
D:/Projects/EmbedPython/main.cpp:49: undefined reference to `_imp__PyErr_Print'
D:/Projects/EmbedPython/main.cpp:55: undefined reference to `_imp__PyErr_Occurred'
D:/Projects/EmbedPython/main.cpp:56: undefined reference to `_imp__PyErr_Print'
D:/Projects/EmbedPython/main.cpp:63: undefined reference to `_imp__PyErr_Print'
D:/Projects/EmbedPython/main.cpp:67: undefined reference to `_imp__Py_FinalizeEx'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\EmbedPython.dir\build.make:97: recipe for target 'EmbedPython.exe' failed
make[2]: *** [EmbedPython.exe] Error 1
make[2]: Leaving directory 'D:/Projects/EmbedPython/cmake-build-debug'
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/EmbedPython.dir/all' failed
make[1]: *** [CMakeFiles/EmbedPython.dir/all] Error 2
make[1]: Leaving directory 'D:/Projects/EmbedPython/cmake-build-debug'
Makefile:82: recipe for target 'all' failed
make: *** [all] Error 2
I had the exactly same problem, just with Python 3.7 while trying to build the example from the Python manual.
My system is a 64-bit Windows, the installed Python is a 64-bit 3.7 (from Anaconda3), and the compiler is a 32-bit MinGW 5.3.0 (from Qt 5.11).
The simplest solution that worked for me is the following:
Download Windows x86 embeddable zip file from this page.
Put the content of that archive to a folder inside the project you're building.
Do not install anything from that archive and do not put it on the system PATH.
Add the above folder to the gcc library search path, using: -L"path/to/folder/"
Add the python library to the linker, using -l"python37" ( replace 37 with whatever version you download)
As noted here (this was a hard one to find!), add a definition, using -DPy_BUILD_CORE_BUILTIN=1 (It is also possible to write #define DPy_BUILD_CORE_BUILTIN 1 just before #include-ing the Python header, though I would not recommend it)
Provide the path to the Python headers, using -I"path/to/include". I used the one from Anaconda, e.g. -I"c:/Users/user/Anaconda3/include/". Any installed header will do, just make sure its from the same version (headers from an older version might also be used, but this may cause a rupture in the space-time continuum)
Make sure that #include <Python.h> is before any other include, as stated in the manual.
As a side note, the MinGW linker (ld) is perfectly content, for many years now, if you just give it the "dll" file. No "lib", nor "a", is needed if you don't have one and only perform dynamic linking. This is why I just told the linker to use python37.
It it actually smart enough to look for files like python37.lib, python37.dll & libpython37.a.
Also note that the "embedable zip" is just the bare minimum needed for, well, embedding Python.
And as a last comment, contrary to what is stated here, there is no problem whatsoever linking from GCC with a library compiled using MSVS (and vice versa), as long as the library uses the plain C interface, since that interface is pretty much the only thing that is compatible across different compilers for any given platform.
This is pretty much the exact reason why Python is using the C interface (and nothing else, not even C++) for extending & embedding - to allow code written in any language, using any tool set, to interface with Python.
I had the same problem.
probably the problem is because of using 32 bit MinGW and 64 bit Python. you should install 32 bit version of python
Hope it will be useful to you :-)
When I generate LLVM IR Code from C++, I can use the console command clang++ -emit-llvm –S test.cpp to get a test.ll file which is the LLVM IR I want.
To get an executable these are the steps to follow:
llvm-as test.ll -> gives me the test.bc file.
llc test.bc --o test.s -> gives me the test.s file.
clang++ test.s -o test.native -> gives me a native file that i can execute.
For C++ this works just fine.
In theory, should the same steps apply when I write Rust or Python Code?
I take my Rust code and get the LLVM IR by typing rustc test.rs --emit llvm-ir. This gives me the test.ll file again.
For Python, I use "Numba" and get the LLVM IR by typing numba --dump-llvm test.py> test.llwhich also gives me the test.ll file.
The steps to generate an executable from those .ll files should be the same.
They work up until the last step that creates the native executable:
Python Error
/tmp/test-9aa440.o: In function 'main':
test.bc:(.text+0x67): undefined reference to 'numba_gil_ensure'
test.bc:(.text+0x79): undefined reference to 'numba_unpickle'
test.bc:(.text+0x84): undefined reference to 'PyObject_Str'
test.bc:(.text+0x8f): undefined reference to 'PyString_AsString'
test.bc:(.text+0xa1): undefined reference to 'PySys_WriteStdout'
test.bc:(.text+0xa9): undefined reference to 'Py_DecRef'
test.bc:(.text+0xb1): undefined reference to 'Py_DecRef'
test.bc:(.text+0xbd): undefined reference to 'PySys_WriteStdout'
test.bc:(.text+0xc5): undefined reference to 'numba_gil_release'
test.bc:(.text+0xff): undefined reference to 'numba_gil_ensure'
test.bc:(.text+0x10b): undefined reference to 'PySys_WriteStdout'
test.bc:(.text+0x113): undefined reference to 'numba_gil_release'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Rust Error
/tmp/main-5e59bd.o: In function ‘main::sum::h514304ffa40dd7c3’:
main.bc:(.text+0xf): undefined reference to ‘core::panicking::panic::h2596388ccef1871c’
/tmp/main-5e59bd.o: In function ‘main’: main.bc:(.text+0x53): undefined reference to ‘std::rt::lang_start::h65647f6e36cffdae’
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What I get from this is that clang doesn't understand the Rust/Python specific parts of the LLVM IR file (e.g. "PyObject" in Python or "panic" from Rust) that were used to generate the .bc, .s and in theory the .native files.
But why are those even in the IR in the first place? Shouldn't the LLVM IR be uniform and those parts be transformed so the LLVM toolchain can work with them?
As far as I know LLVMs modularity should allow those steps by using LLVM IR. Is there maybe another way to do this i don't know about?
Can I generate the IRs from those languages in some other way that gives "pure" LLVM IR that clang understands, or could I still generate executables from those files, but in some other way without clang?
I can speak of Rust code:
You need to link Rust's std library something like this:
$(LLI) -load /Users/Stanislaw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/libstd-f5a209a9.dylib ./target/debug/jitrust.bc
See the full example of Makefile I use here.
P.S. I would assume that the same goes about Python. You have to also supply libraries which contain this "unreferenced" stuff.
I'm trying to install the leven package (https://pypi.python.org/pypi/leven/) using python 2.7.10, windows 10, and mingw. I'm getting the following error:
"collect2.exe: error: ld returned 1 exit status"
Any help on this would be greatly appreciate it. I've been trying to install this for days now. I've overcome several problems includying a previous collect2.exe error using this solution: Unable to Install pyslalib package using python2.7 / MINGW on Windows 10
However, after fixing that issue another error surged. Here is the error:
C:\bin\leven-1.0.4.tar\dist\leven-1.0.4>python setup.py install
running install
running bdist_egg
running egg_info
writing requirements to leven.egg-info\requires.txt
writing leven.egg-info\PKG-INFO
writing top-level names to leven.egg-info\top_level.txt
writing dependency_links to leven.egg-info\dependency_links.txt
reading manifest file 'leven.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'leven.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_py
running build_ext
building 'leven._levenshtein' extension
C:\Program Files (x86)\CodeBlocks\MinGW\bin\gcc.exe -mdll -O -Wall -Ileven -IC:\Python27\include -IC:\Python27\PC -c leven/_levenshtein.cpp -o build\temp.win32-2.7\Release\leven\_levenshtein.o
leven/_levenshtein.cpp: In function 'void __Pyx_RaiseArgtupleInvalid(const char*, int, Py_ssize_t, Py_ssize_t, Py_ssize_t)':
leven/_levenshtein.cpp:1400:59: warning: unknown conversion type character 'z' in format [-Wformat]
leven/_levenshtein.cpp:1400:59: warning: format '%s' expects argument of type 'char*', but argument 5 has type 'Py_ssize_t {aka int}' [-Wformat]
leven/_levenshtein.cpp:1400:59: warning: unknown conversion type character 'z' in format [-Wformat]
leven/_levenshtein.cpp:1400:59: warning: too many arguments for format [-Wformat-extra-args]
writing build\temp.win32-2.7\Release\leven\_levenshtein.def
C:\Program Files (x86)\CodeBlocks\MinGW\bin\g++.exe -mdll -static --entry _DllMain#12 -out-implib=build\temp.win32-2.7\Release\leven\lib_levenshtein.a --def build\temp.win32-2.7\Release\leven\_levenshtein.def -s build\temp.win32-2.7\Release\leven\_levenshtein.o -LC:\Python27\libs -LC:\Python27\PCbuild -lpython27 -lmsvcr90 -o build\lib.win32-2.7\leven\_levenshtein.pyd
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xbe): undefined reference to `_imp__PyExc_TypeError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xc9): undefined reference to `_imp__PyErr_Format'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x114): undefined reference to `_imp__PyErr_Occurred'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x280): undefined reference to `_imp__PyExc_MemoryError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x293): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2b9): undefined reference to `_imp__PyExc_TypeError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2cc): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2f2): undefined reference to `_imp__PyExc_ValueError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x305): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x32b): undefined reference to `_imp__PyExc_ValueError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x33e): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x364): undefined reference to `_imp__PyExc_IOError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x377): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x39d): undefined reference to `_imp__PyExc_IndexError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x3b0): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x3d6): undefined reference to `_imp__PyExc_OverflowError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x3e9): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x40f): undefined reference to `_imp__PyExc_ArithmeticError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x422): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x448): undefined reference to `_imp__PyExc_ArithmeticError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x45b): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x47e): undefined reference to `_imp__PyExc_RuntimeError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x491): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x4b1): undefined reference to `_imp__PyExc_RuntimeError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x4c4): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x502): undefined reference to `_imp__PyString_FromString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x515): undefined reference to `_imp__PyImport_Import'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x53e): undefined reference to `_imp__PyString_FromString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x555): undefined reference to `_imp__PyObject_GetAttr'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x5a5): undefined reference to `_imp__PyExc_TypeError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x5b0): undefined reference to `_imp__PyErr_Format'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x5f1): undefined reference to `_imp__PyOS_snprintf'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x60a): undefined reference to `_imp__PyErr_WarnEx'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x62f): undefined reference to `_imp__PyExc_ValueError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x63a): undefined reference to `_imp__PyErr_Format'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x6f9): undefined reference to `_imp__PyString_FromString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x728): undefined reference to `_imp__PyString_FromFormat'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x739): undefined reference to `_imp__PyString_FromString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x79f): undefined reference to `_imp__PyCode_New'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x80b): undefined reference to `_imp__PyMem_Malloc'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x89e): undefined reference to `_imp__PyMem_Realloc'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x903): undefined reference to `_imp__PyModule_GetDict'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x91c): undefined reference to `_imp___PyThreadState_Current'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x927): undefined reference to `_imp__PyFrame_New'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x93d): undefined reference to `_imp__PyTraceBack_Here'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x998): undefined reference to `_imp__PyString_FromString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xaa7): undefined reference to `_imp__PyDict_Size'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xaec): undefined reference to `_imp__PyDict_GetItem'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xb23): undefined reference to `_imp__PyDict_GetItem'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xb9b): undefined reference to `_imp__PyDict_GetItem'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xc51): undefined reference to `_imp___PyString_Eq'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xcdc): undefined reference to `_imp___PyString_Eq'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xd40): undefined reference to `_imp__PyUnicodeUCS2_Compare'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xd50): undefined reference to `_imp__PyErr_Occurred'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xde2): undefined reference to `_imp__PyUnicodeUCS2_Compare'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xdf2): undefined reference to `_imp__PyErr_Occurred'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xe53): undefined reference to `_imp__PyDict_Next'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xe7b): undefined reference to `_imp__PyString_AsString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xe94): undefined reference to `_imp__PyExc_TypeError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xe9f): undefined reference to `_imp__PyErr_Format'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xeb9): undefined reference to `_imp__PyExc_TypeError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xecf): undefined reference to `_imp__PyErr_Format'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xeef): undefined reference to `_imp__PyString_AsString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xf08): undefined reference to `_imp__PyExc_TypeError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xf13): undefined reference to `_imp__PyErr_Format'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xf8a): undefined reference to `_imp__PyObject_Size'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xfa0): undefined reference to `_imp__PyObject_Size'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0xfea): undefined reference to `_imp__PyString_AsStringAndSize'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1012): undefined reference to `_imp__PyErr_Occurred'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1048): undefined reference to `_imp__PyString_AsStringAndSize'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1070): undefined reference to `_imp__PyErr_Occurred'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x14d1): undefined reference to `_imp__PyObject_GetAttr'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x14f8): undefined reference to `_imp__PyTuple_New'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1509): undefined reference to `_imp__PyUnicode_Type'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1549): undefined reference to `_imp__PyObject_Call'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x15b6): undefined reference to `_imp__PyTuple_New'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x15e3): undefined reference to `_imp__PyObject_Call'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x161c): undefined reference to `_imp___Py_NoneStruct'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x163e): undefined reference to `_imp___Py_NoneStruct'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x165c): undefined reference to `_imp__PyTraceBack_Type'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x166e): undefined reference to `_imp__PyExc_TypeError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1684): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x16ca): undefined reference to `_imp__PyErr_NormalizeException'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x16e6): undefined reference to `_imp__PyExc_TypeError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x16fc): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1716): undefined reference to `_imp__PyExc_BaseException'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1737): undefined reference to `_imp__PyType_IsSubtype'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1748): undefined reference to `_imp__PyExc_TypeError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1753): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x176b): undefined reference to `_imp___PyThreadState_Current'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1911): undefined reference to `_imp___Py_TrueStruct'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x191a): undefined reference to `_imp___Py_ZeroStruct'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1927): undefined reference to `_imp___Py_NoneStruct'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1946): undefined reference to `_imp__PyObject_IsTrue'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x19a2): undefined reference to `_imp__PyGILState_Ensure'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x19b3): undefined reference to `_imp__PyExc_ZeroDivisionError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x19be): undefined reference to `_imp__PyErr_Format'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x19cb): undefined reference to `_imp__PyGILState_Release'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1a1d): undefined reference to `_imp__PyFloat_FromDouble'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1a46): undefined reference to `_imp__PyLong_FromUnsignedLong'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1f1c): undefined reference to `_imp__PyString_Type'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1fbd): undefined reference to `_imp__PyOS_snprintf'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x1fc5): undefined reference to `_imp__Py_GetVersion'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x202b): undefined reference to `_imp__PyOS_snprintf'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2044): undefined reference to `_imp__PyErr_WarnEx'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2059): undefined reference to `_imp__PyTuple_New'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x207b): undefined reference to `_imp__PyString_FromStringAndSize'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x20b5): undefined reference to `_imp__Py_InitModule4'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x20cd): undefined reference to `_imp__PyModule_GetDict'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x20e9): undefined reference to `_imp__PyImport_AddModule'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2110): undefined reference to `_imp__PyObject_SetAttrString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2131): undefined reference to `_imp__PyString_FromStringAndSize'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2137): undefined reference to `_imp__PyString_InternFromString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2159): undefined reference to `_imp__PyUnicodeUCS2_DecodeUTF8'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x21b9): undefined reference to `_imp__PyObject_SetAttrString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2203): undefined reference to `_imp__PyObject_GetAttr'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x221f): undefined reference to `_imp__PyExc_NameError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x222a): undefined reference to `_imp__PyErr_Format'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x22f2): undefined reference to `_imp__PyCode_New'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2377): undefined reference to `_imp___Py_ZeroStruct'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x239c): undefined reference to `_imp__PyCFunction_NewEx'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x23c1): undefined reference to `_imp__PyDict_SetItem'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x23e1): undefined reference to `_imp__PyDict_New'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2406): undefined reference to `_imp__PyDict_SetItem'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2429): undefined reference to `_imp__PyDict_SetItem'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x24a7): undefined reference to `_imp__PyErr_Occurred'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x24bc): undefined reference to `_imp__PyExc_ImportError'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x24c7): undefined reference to `_imp__PyErr_SetString'
build\temp.win32-2.7\Release\leven\_levenshtein.o:_levenshtein.cpp:(.text+0x2558): undefined reference to `_imp__PyTuple_Pack'
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin\\g++.exe' failed with exit status 1
C:\bin\leven-1.0.4.tar\dist\leven-1.0.4>
Thank you in advance.
These errors are references to python core library (libpython27.a from C:\Python27\libs). Make sure:
it is exists and match your gcc architecture. These errors are often appear when you are using 32-bit gcc and 64-bit libraries.
I see you are using pexports to create this library, it may work wrong too, see http://www.mingw.org/wiki/msvc_and_mingw_dlls - it can add additional _ to all exported names and you need to strip it as described:
pexports python27.dll | sed "s/^_//" > python27.def
Python standard Windows distribution built with MSVC 2008 and linked to msvcr90.dll, when mingw-gcc linking binaries with msvcrt.dll - it can cause a lot of problems(crashes). You need to follow this guide to make your gcc link with msvcr90.dll
I am trying to compile a Python library (CEGUI can build Python modules, its editor relies on that) that needs to link against boost-python. So I built boost, with --with-python and it built just fine.
However, as soon as the .pyd is linked, I get undefined references:
Linking CXX shared module ..\..\..\..\..\bin\PyCEGUI.pyd
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x97): undefined reference to `_imp___ZN5boost6python7objects10class_baseC2EPKcjPKNS0_9type_infoES4_'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x9c): undefined reference to `_imp___ZN5boost6python9converter8registry6insertEPFPvP7_objectEPFvS5_PNS1_30rvalue_from_python_stage1_dataEENS0_9type_infoEPFPK11_typeobjectvE
'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0xcc): undefined reference to `_imp___ZN5boost6python7objects23register_dynamic_id_auxENS0_9type_infoEPFSt4pairIPvS2_ES4_E'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0xf4): undefined reference to `_imp___ZN5boost6python7objects8add_castENS0_9type_infoES2_PFPvS3_Eb'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x1cd): undefined reference to `_imp___ZN5boost6python7objects17copy_class_objectERKNS0_9type_infoES4_'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x20d): undefined reference to `_imp___ZN5boost6python9converter8registry6insertEPFP7_objectPKvENS0_9type_infoEPFPK11_typeobjectvE'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x245): undefined reference to `_imp___ZN5boost6python7objects10class_base17set_instance_sizeEj'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x281): undefined reference to `_imp___ZN5boost6python7objects15function_objectERKNS1_11py_functionERKSt4pairIPKNS0_6detail7keywordES9_E'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x2f2): undefined reference to `_imp___ZN5boost6python7objects16add_to_namespaceERKNS0_3api6objectEPKcS5_S7_'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x348): undefined reference to `_imp___ZN5boost6python6detail13current_scopeE'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x4d1): undefined reference to `_imp___ZN5boost6python9converter8registry9push_backEPFPvP7_objectEPFvS5_PNS1_30rvalue_from_python_stage1_dataEENS0_9type_infoEPFPK11_typeobjectvE'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x636): undefined reference to `_imp___ZN5boost6python7objects16add_to_namespaceERKNS0_3api6objectEPKcS5_'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x1246): undefined reference to `_imp___ZN5boost6python6detail13current_scopeE'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x1267): undefined reference to `_imp___ZN5boost6python6detail13current_scopeE'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):
bad reloc address 0x2 in section `.text$_ZN5boost6detail15sp_counted_baseD1Ev[__ZN5boost6detail15sp_counted_baseD1Ev]'
collect2.exe: error: ld returned 1 exit status
cegui\src\ScriptModules\Python\bindings\CMakeFiles\PyCEGUI.dir\build.make:6698: recipe for target 'bin/PyCEGUI.pyd' failed
mingw32-make[2]: *** [bin/PyCEGUI.pyd] Error 1
CMakeFiles\Makefile2:726: recipe for target 'cegui/src/ScriptModules/Python/bindings/CMakeFiles/PyCEGUI.dir/all' failed
mingw32-make[1]: *** [cegui/src/ScriptModules/Python/bindings/CMakeFiles/PyCEGUI.dir/all] Error 2
Makefile:135: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
My first assumption was that it does not link against boost-python, but the link.txt inside the CMake folders shows this:
"C:\Coding\CMake 2.8\bin\cmake.exe" -E remove -f
CMakeFiles\PyCEGUI.dir/objects.a C:\MinGW\bin\ar.exe cr
CMakeFiles\PyCEGUI.dir/objects.a #CMakeFiles\PyCEGUI.dir\objects1.rsp
C:\MinGW\bin\g++.exe -shared -o ..........\bin\PyCEGUI.pyd
-Wl,--major-image-version,0,--minor-image-version,0 -Wl,--whole-archive CMakeFiles\PyCEGUI.dir/objects.a -Wl,--no-whole-archive ..........\lib\libCEGUIBase-0.dll.a C:\Coding\boost_1_53_0\lib\libboost_python-mgw48-mt-1_53.a
C:\Python27\libs\python27.lib
C:\Coding\CEGUI\cegui\dependencies\lib\dynamic\libfreetype.dll.a
C:\Coding\CEGUI\cegui\dependencies\lib\dynamic\libpcre.dll.a -lwinmm
-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
So boost-python is linked against.
I am unsure what could be the problem here. Boost? CEGUI? MinGW?...
Turns out, the problem was that I was using the 64bit version of Python. I downloaded it months ago and just forgot about that little fact.
Now, MinGW can only compile and use 32 bit libraries, not mix in 64 bit. This is what led to boost-python not compiling correctly (it's a wonder it did compile at all) and thus having undefined references when linked against.
Downloading the 32bit version of Python and recompiling boost solved the problems.