很抱歉,如果我複製了一個問題,但我無法找到我在互聯網上任何地方尋找解決方案,但我相信這是一個非常簡單的問題。CMake沒有鏈接Python
我想用一些自定義C++庫擴展python,並用CMake構建我的C++庫。我按照https://docs.python.org/2/extending/extending.html上的說明操作,但它沒有正確編譯。
當我嘗試構建它,我得到的消息:
"C:\Program Files (x86)\JetBrains\CLion 140.2310.6\bin\cmake\bin\cmake.exe" --build C:\Users\pkim2\.clion10\system\cmake\generated\76c451cd\76c451cd\Debug --target parsers -- -j 8
Linking CXX executable parsers.exe
CMakeFiles\parsers.dir/objects.a(main.cpp.obj): In function `spam_system':
C:/code/ground-trac/ground/launch/trunk/Software Support/Data Analysis Scripts/data_review_automation/parsers/main.cpp:9: undefined reference to `_imp__PyArg_ParseTuple'
C:/code/ground-trac/ground/launch/trunk/Software Support/Data Analysis Scripts/data_review_automation/parsers/main.cpp:12: undefined reference to `_imp__Py_BuildValue'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):(.text.startup+0xa7): undefined reference to `[email protected]'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\parsers.dir\build.make:87: recipe for target 'parsers.exe' failed
CMakeFiles\Makefile2:59: recipe for target 'CMakeFiles/parsers.dir/all' failed
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/parsers.dir/rule' failed
mingw32-make.exe[3]: *** [parsers.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/parsers.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/parsers.dir/rule] Error 2
mingw32-make.exe: *** [parsers] Error 2
Makefile:109: recipe for target 'parsers' failed
在此基礎上,我懷疑這是用我的東西聯繫起來的的CMakeLists.txt文件的方式有問題,但我不知道如何正確地做到這一點。這就是我的CMakeLists.txt現在看起來像:
cmake_minimum_required(VERSION 2.8.4)
project(parsers)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
include_directories(C:\\Python27\\include)
link_directories(C:\\Python27\\)
target_link_libraries(python2.7)
add_executable(parsers ${SOURCE_FILES})
在世界上我怎麼得到這個東西編譯正確?我正在運行Windows 7 64位,並使用CLion作爲我的IDE。
我通常只是一聲我的頭撞在牆上了幾個小時,然後放棄 – 2015-03-02 18:55:56
我想這樣做,太:(... – 2015-03-02 19:41:10