2017-05-24 4 views
1

Versuchen Sie, Python3.6 in C++ auf Win10 64-Bit-System einzubetten. Python wird von python-3.6.1-amd64.exe installiert. Die CMakeList.txt zeigt unterEmbeded python3.6 mit MinGW in C++ fail on Verknüpfung

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}) 

Und CMake die Python-Paket gefunden.

PYTHON_INCLUDE_DIR C:/Program Files (x86)/Python36/include 
PYTHON_LIBRARY C:/Program Files (x86)/Python36/libs/python36.lib 

Find a comment on github es geht um das 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}) 

Die folgenden Fehler ist, was ich bin vor.

Nicht sicher, was zu tun ist, um das Projekt laufen zu lassen. Jede Hilfe würde geschätzt werden.

EDIT: das Ergebnis von 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 
+1

Bitte zeigen Sie Ihre CMakeLists.txt und die Ausgabe von 'VERBOSE machen = 1 '. Bitte posten Sie auch keine Bilder von Texten. –

+0

@ n.m. Ich habe die Ausgabe von make 'VERBOSE = 1' hinzugefügt und das Bild von der CMake-GUI entfernt. –

+1

Sie müssen 'target_link_libraries' verwenden. Mit "add_executable" können Sie Quellen und keine Bibliotheken angeben. –

Antwort

0

ich hatte das gleiche Problem.

wahrscheinlich ist das Problem wegen der Verwendung von 32-Bit-MinGW und 64-Bit-Python. Sie sollten 32-Bit-Version von Python

Hoffe, dass es nützlich sein wird, die Sie installieren :-)