Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cmake链接错误-订单依赖还是其他?_Cmake_G++ - Fatal编程技术网

cmake链接错误-订单依赖还是其他?

cmake链接错误-订单依赖还是其他?,cmake,g++,Cmake,G++,我正试图建立在Ubuntu 14.04上。它可以编译,但不会链接 我读过(那里的错误看起来很像我看到的)和。我确信找到了罪魁祸首,但当我查看构建文件时,Python库已经是链接顺序中的最后一个: kevin@aphrodite:~/src/Sigil$ grep -r 'target_link_libraries' . ./src/CMakeLists.txt~:target_link_libraries( ${PROJECT_NAME} ${QT_MAIN} ${HUNSPELL_LIBRAR

我正试图建立在Ubuntu 14.04上。它可以编译,但不会链接

我读过(那里的错误看起来很像我看到的)和。我确信找到了罪魁祸首,但当我查看构建文件时,Python库已经是链接顺序中的最后一个:

kevin@aphrodite:~/src/Sigil$ grep -r 'target_link_libraries' .
./src/CMakeLists.txt~:target_link_libraries( ${PROJECT_NAME} ${QT_MAIN} ${HUNSPELL_LIBRARIES} ${PCRE_LIBRARIES} gumbo ${MINIZIP_LIBRARIES} ${BOOST_LIBS} ${XERCES_LIBRARIES} ${XERCESEXTENSIONS_LIBRARIES} ${PYTHON_LIBRARIES} )
./src/CMakeLists.txt:target_link_libraries( ${PROJECT_NAME} ${QT_MAIN} ${HUNSPELL_LIBRARIES} ${PCRE_LIBRARIES} gumbo ${MINIZIP_LIBRARIES} ${BOOST_LIBS} ${XERCES_LIBRARIES} ${XERCESEXTENSIONS_LIBRARIES} ${PYTHON_LIBRARIES} )
./3rdparty/minizip/CMakeLists.txt:target_link_libraries( ${PROJECT_NAME} ${ZLIB_LIBRARIES} )
./cmake_extras/FindPythonLibs.cmake:#    target_link_libraries(${_NAME} ${PYTHON_LIBRARIES})
我对cmake不太熟悉,所以我被难住了。我能想到的另一件事是,我安装了两个不同版本的Python(2.7和3.4),因为许多核心Ubuntu包需要2.x,而Sigil需要3.x。如果这是问题所在,我不知道该怎么办

下面是成功的build命令:

cmake -G "Unix Makefiles" -DCMAKE_PREFIX_PATH=/home/kevin/local/qt/5.4/gcc_64/lib/cmake -DCMAKE_BUILD_TYPE=Release -DPYTHON_LIBRARY=/usr/bin/python3.4 -DFORCE_BUNDLED_COPIES=1 /home/kevin/src/Sigil
这是link命令,它失败了。这里有冒烟的枪吗

kevin@aphrodite:~/src/Sigil$ make linuxbinpkg
[  1%] Automatic moc for target sigil
[  1%] Built target sigil_automoc
[  5%] Built target gumbo
[ 10%] Built target zlib
[ 13%] Built target hunspell
[ 14%] Built target minizip
[ 21%] Built target pcre
Linking CXX executable ../bin/sigil
/usr/bin/ld: error in /usr/bin/python3.4(.eh_frame); no .eh_frame_hdr table will be created.
CMakeFiles/sigil.dir/Misc/EmbeddedPython.cpp.o: In function `EmbeddedPython::instance()':
EmbeddedPython.cpp:(.text+0x26): undefined reference to `Py_Initialize'
EmbeddedPython.cpp:(.text+0x2b): undefined reference to `PyEval_InitThreads'
EmbeddedPython.cpp:(.text+0x30): undefined reference to `PyEval_SaveThread'
CMakeFiles/sigil.dir/Misc/EmbeddedPython.cpp.o: In function `EmbeddedPython::EmbeddedPython()':
EmbeddedPython.cpp:(.text+0x127): undefined reference to `Py_Initialize'
EmbeddedPython.cpp:(.text+0x12c): undefined reference to `PyEval_InitThreads'
EmbeddedPython.cpp:(.text+0x131): undefined reference to `PyEval_SaveThread'
CMakeFiles/sigil.dir/Misc/EmbeddedPython.cpp.o: In function `EmbeddedPython::~EmbeddedPython()':
EmbeddedPython.cpp:(.text+0x24e): undefined reference to `PyEval_RestoreThread'
EmbeddedPython.cpp:(.text+0x253): undefined reference to `Py_Finalize'
EmbeddedPython.cpp:(.text+0x27c): undefined reference to `PyEval_RestoreThread'
EmbeddedPython.cpp:(.text+0x281): undefined reference to `Py_Finalize'
EmbeddedPython.cpp:(.text+0x2aa): undefined reference to `PyEval_RestoreThread'
EmbeddedPython.cpp:(.text+0x2af): undefined reference to `Py_Finalize'
EmbeddedPython.cpp:(.text+0x2d8): undefined reference to `PyEval_RestoreThread'
EmbeddedPython.cpp:(.text+0x2dd): undefined reference to `Py_Finalize'
EmbeddedPython.cpp:(.text+0x306): undefined reference to `PyEval_RestoreThread'
CMakeFiles/sigil.dir/Misc/EmbeddedPython.cpp.o: In function `EmbeddedPython::addToPythonSysPath(QString const&)':
EmbeddedPython.cpp:(.text+0x32a): undefined reference to `PyGILState_Ensure'
EmbeddedPython.cpp:(.text+0x339): undefined reference to `PySys_GetObject'
EmbeddedPython.cpp:(.text+0x35c): undefined reference to `PyUnicode_FromString'
EmbeddedPython.cpp:(.text+0x38d): undefined reference to `PyList_Append'
EmbeddedPython.cpp:(.text+0x3b6): undefined reference to `PyGILState_Release'
CMakeFiles/sigil.dir/Misc/EmbeddedPython.cpp.o: In function `EmbeddedPython::QVariantToPyObject(QVariant&)':
EmbeddedPython.cpp:(.text+0xd97): undefined reference to `Py_BuildValue'
EmbeddedPython.cpp:(.text+0xdc9): undefined reference to `Py_BuildValue'
EmbeddedPython.cpp:(.text+0xdeb): undefined reference to `Py_BuildValue'
EmbeddedPython.cpp:(.text+0xe0e): undefined reference to `Py_BuildValue'
EmbeddedPython.cpp:(.text+0xe31): undefined reference to `Py_BuildValue'
CMakeFiles/sigil.dir/Misc/EmbeddedPython.cpp.o:EmbeddedPython.cpp:(.text+0xe57): more undefined references to `Py_BuildValue' follow
CMakeFiles/sigil.dir/Misc/EmbeddedPython.cpp.o: In function `EmbeddedPython::QVariantToPyObject(QVariant&)':
EmbeddedPython.cpp:(.text+0xe82): undefined reference to `PyList_New'
EmbeddedPython.cpp:(.text+0xeff): undefined reference to `PyList_SetItem'
EmbeddedPython.cpp:(.text+0x103d): undefined reference to `PyUnicode_FromKindAndData'
EmbeddedPython.cpp:(.text+0x10a4): undefined reference to `PyList_New'
EmbeddedPython.cpp:(.text+0x114e): undefined reference to `PyUnicode_FromKindAndData'
EmbeddedPython.cpp:(.text+0x115c): undefined reference to `PyList_SetItem'
EmbeddedPython.cpp:(.text+0x124b): undefined reference to `Py_BuildValue'
EmbeddedPython.cpp:(.text+0x1299): undefined reference to `Py_BuildValue'
CMakeFiles/sigil.dir/Misc/EmbeddedPython.cpp.o: In function `EmbeddedPython::PyObjectToQVariant(_object*, bool)':
EmbeddedPython.cpp:(.text+0x179a): undefined reference to `PyFloat_Type'
EmbeddedPython.cpp:(.text+0x17a8): undefined reference to `PyType_IsSubtype'
EmbeddedPython.cpp:(.text+0x180a): undefined reference to `PyUnicode_AsUTF8'
EmbeddedPython.cpp:(.text+0x1944): undefined reference to `PyFloat_AsDouble'
EmbeddedPython.cpp:(.text+0x19e4): undefined reference to `PyLong_AsLongLong'
EmbeddedPython.cpp:(.text+0x1bec): undefined reference to `PyBytes_AsString'
EmbeddedPython.cpp:(.text+0x1dd4): undefined reference to `_PyUnicode_Ready'
EmbeddedPython.cpp:(.text+0x1e03): undefined reference to `PyTuple_Size'
EmbeddedPython.cpp:(.text+0x1e2f): undefined reference to `PyTuple_GetItem'
EmbeddedPython.cpp:(.text+0x1f8b): undefined reference to `PyList_Size'
EmbeddedPython.cpp:(.text+0x1fb7): undefined reference to `PyList_GetItem'
CMakeFiles/sigil.dir/Misc/EmbeddedPython.cpp.o: In function `EmbeddedPython::getPythonErrorTraceback(bool)':
EmbeddedPython.cpp:(.text+0x25e0): undefined reference to `PyErr_Fetch'
EmbeddedPython.cpp:(.text+0x25f3): undefined reference to `PyErr_NormalizeException'
EmbeddedPython.cpp:(.text+0x2604): undefined reference to `PyImport_ImportModule'
EmbeddedPython.cpp:(.text+0x263c): undefined reference to `PyObject_CallMethod'
EmbeddedPython.cpp:(.text+0x2793): undefined reference to `PyErr_Clear'
CMakeFiles/sigil.dir/Misc/EmbeddedPython.cpp.o: In function `EmbeddedPython::runInPython(QString const&, QString const&, QList<QVariant> const&, int*, QString&, bool)':
EmbeddedPython.cpp:(.text+0x2b52): undefined reference to `PyGILState_Ensure'
EmbeddedPython.cpp:(.text+0x2bbc): undefined reference to `PyUnicode_FromString'
EmbeddedPython.cpp:(.text+0x2bee): undefined reference to `PyImport_Import'
EmbeddedPython.cpp:(.text+0x2c1b): undefined reference to `PyObject_GetAttrString'
EmbeddedPython.cpp:(.text+0x2c54): undefined reference to `PyCallable_Check'
EmbeddedPython.cpp:(.text+0x2c71): undefined reference to `PyErr_Occurred'
EmbeddedPython.cpp:(.text+0x2d37): undefined reference to `PyGILState_Release'
EmbeddedPython.cpp:(.text+0x2e9f): undefined reference to `PyTuple_New'
EmbeddedPython.cpp:(.text+0x2f35): undefined reference to `PyTuple_SetItem'
EmbeddedPython.cpp:(.text+0x3005): undefined reference to `PyObject_CallObject'
CMakeFiles/sigil.dir/Misc/EmbeddedPython.cpp.o: In function `EmbeddedPython::callPyObjMethod(PyObjectPtr&, QString const&, QList<QVariant> const&, int*, QString&, bool)':
EmbeddedPython.cpp:(.text+0x318d): undefined reference to `PyGILState_Ensure'
EmbeddedPython.cpp:(.text+0x31f4): undefined reference to `PyObject_GetAttrString'
EmbeddedPython.cpp:(.text+0x3226): undefined reference to `PyCallable_Check'
EmbeddedPython.cpp:(.text+0x3243): undefined reference to `PyErr_Occurred'
EmbeddedPython.cpp:(.text+0x32cd): undefined reference to `PyGILState_Release'
EmbeddedPython.cpp:(.text+0x33b9): undefined reference to `PyTuple_New'
EmbeddedPython.cpp:(.text+0x3437): undefined reference to `PyTuple_SetItem'
EmbeddedPython.cpp:(.text+0x34f6): undefined reference to `PyObject_CallObject'
CMakeFiles/sigil.dir/Misc/EmbeddedPython.cpp.o: In function `EmbeddedPython::~EmbeddedPython()':
EmbeddedPython.cpp:(.text+0x30c): undefined reference to `Py_Finalize'
CMakeFiles/sigil.dir/Misc/PyObjectPtr.cpp.o: In function `PyObjectPtr::~PyObjectPtr()':
PyObjectPtr.cpp:(.text+0x1f): undefined reference to `PyGILState_Ensure'
CMakeFiles/sigil.dir/Misc/PyObjectPtr.cpp.o: In function `PyObjectPtr::setNewRef(_object*)':
PyObjectPtr.cpp:(.text+0x8a): undefined reference to `PyGILState_Ensure'
PyObjectPtr.cpp:(.text+0xa3): undefined reference to `PyGILState_Release'
CMakeFiles/sigil.dir/Misc/PyObjectPtr.cpp.o: In function `PyObjectPtr::fromVariant(QVariant const&)':
PyObjectPtr.cpp:(.text+0x14d): undefined reference to `PyGILState_Ensure'
PyObjectPtr.cpp:(.text+0x16c): undefined reference to `PyGILState_Release'
PyObjectPtr.cpp:(.text+0x183): undefined reference to `PyGILState_Ensure'
PyObjectPtr.cpp:(.text+0x1a4): undefined reference to `PyGILState_Release'
PyObjectPtr.cpp:(.text+0x1c0): undefined reference to `PyGILState_Ensure'
PyObjectPtr.cpp:(.text+0x1df): undefined reference to `PyGILState_Release'
PyObjectPtr.cpp:(.text+0x203): undefined reference to `PyGILState_Ensure'
PyObjectPtr.cpp:(.text+0x220): undefined reference to `PyGILState_Release'
CMakeFiles/sigil.dir/Misc/PyObjectPtr.cpp.o: In function `PyObjectPtr::setObject(_object*)':
PyObjectPtr.cpp:(.text+0x42a): undefined reference to `PyGILState_Ensure'
PyObjectPtr.cpp:(.text+0x444): undefined reference to `PyGILState_Release'
CMakeFiles/sigil.dir/Misc/PyObjectPtr.cpp.o: In function `PyObjectPtr::~PyObjectPtr()':
PyObjectPtr.cpp:(.text+0x3d): undefined reference to `PyGILState_Release'
PyObjectPtr.cpp:(.text+0x5f): undefined reference to `PyGILState_Release'
CMakeFiles/sigil.dir/Misc/PyObjectPtr.cpp.o: In function `QtMetaTypePrivate::QMetaTypeFunctionHelper<PyObjectPtr, true>::Destruct(void*)':
PyObjectPtr.cpp:(.text._ZN17QtMetaTypePrivate23QMetaTypeFunctionHelperI11PyObjectPtrLb1EE8DestructEPv[_ZN17QtMetaTypePrivate23QMetaTypeFunctionHelperI11PyObjectPtrLb1EE8DestructEPv]+0xf): undefined reference to `PyGILState_Ensure'
PyObjectPtr.cpp:(.text._ZN17QtMetaTypePrivate23QMetaTypeFunctionHelperI11PyObjectPtrLb1EE8DestructEPv[_ZN17QtMetaTypePrivate23QMetaTypeFunctionHelperI11PyObjectPtrLb1EE8DestructEPv]+0x2d): undefined reference to `PyGILState_Release'
PyObjectPtr.cpp:(.text._ZN17QtMetaTypePrivate23QMetaTypeFunctionHelperI11PyObjectPtrLb1EE8DestructEPv[_ZN17QtMetaTypePrivate23QMetaTypeFunctionHelperI11PyObjectPtrLb1EE8DestructEPv]+0x4f): undefined reference to `PyGILState_Release'
CMakeFiles/sigil.dir/Misc/PyObjectPtr.cpp.o: In function `QtMetaTypePrivate::QMetaTypeFunctionHelper<PyObjectPtr, true>::Delete(void*)':
PyObjectPtr.cpp:(.text._ZN17QtMetaTypePrivate23QMetaTypeFunctionHelperI11PyObjectPtrLb1EE6DeleteEPv[_ZN17QtMetaTypePrivate23QMetaTypeFunctionHelperI11PyObjectPtrLb1EE6DeleteEPv]+0x14): undefined reference to `PyGILState_Ensure'
PyObjectPtr.cpp:(.text._ZN17QtMetaTypePrivate23QMetaTypeFunctionHelperI11PyObjectPtrLb1EE6DeleteEPv[_ZN17QtMetaTypePrivate23QMetaTypeFunctionHelperI11PyObjectPtrLb1EE6DeleteEPv]+0x2d): undefined reference to `PyGILState_Release'
collect2: error: ld returned 1 exit status
make[3]: *** [bin/sigil] Error 1
make[2]: *** [src/CMakeFiles/sigil.dir/all] Error 2
make[1]: *** [src/CMakeFiles/linuxbinpkg.dir/rule] Error 2
make: *** [linuxbinpkg] Error 2

首先,尝试手动输入以下命令行

[省略,如果感兴趣,请参见编辑历史记录]

基本上我只是用Python2.7替换了Python3.4;请在/usr/bin中再次检查库的名称


我看到你现在有了一个解决方案,根本问题是在CMakeLists.txt中,这一行

find_package (PythonLibs 3.4)
应该是:

find_package (PythonLibs 3.4 REQUIRED)

Antonio建议调用
消息(状态为“PYTHON_LIBRARIES=${PYTHON_LIBRARIES}”)
使我想到了/facepalm

在我的
cmake
命令中,我放置了
-DPYTHON\u LIBRARY=/usr/bin/python3.4
。这是一个可执行文件,而不是库。我不确定导致我把它放在那里的事件的确切顺序,但我认为是这样的:

  • 尝试只安装Python2.7进行构建
    cmake
    失败,因为它找不到合适的Python版本
  • 已安装Python3.4。如果我在此时再次尝试构建,可能它失败了,因为
    cmake
    没有真正的“干净”选项,所以可能它被困在Python2.7上
  • 放进那条伪造的图书馆通道
因此,
cmake
成功了,显然对它实际上没有用于任何事情的伪路径感到满意,只是在Makefile中写入

在用一个干净的项目树重新开始之后,我看到了我以前从未见过的这一行:

Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (found suitable version "3.4", minimum required is "3.4") 

现在
make
工作了

尝试使用
make VERBOSE=1
,这样我们就可以看到链接命令了。这很奇怪:在-o
。/bin/sigil
之后有一个很长的列表(元素中有一个
/usr/bin/python3.4
),但是没有-l选项(链接库)或-l(链接目录)。仅供参考,可以使用cmake命令
link\u directories
指定链接目录。相同错误<代码>ls/usr/bin/python*显示
/usr/bin/python2.7/usr/bin/python3/usr/bin/python3.4-config/usr/bin/python3.4m-config/usr/bin/python3m/usr/bin/python2/usr/bin/python2.7-config/usr/bin/python3.4/usr/bin/python3.4m/usr/bin/python3-config/usr/bin/python3-config。除了
/usr/bin/python2.7
/usr/bin/python3.4
/usr/bin/python3.4m
之外,所有的都是符号链接。在CMakeLists.txt中,添加
消息(状态“PYTHON_库=${PYTHON_库})
:您将看到哪个PYTHON库(理论上)正在尝试链接。我仍然不明白为什么在生成的make命令中没有
-l
语句。在命令行中获取
-lpython2.7
。@KevinKrumwiede消息应该在
查找包(PythonLibs 3.4)之后打印
。也许
-lpython3.4
也能解决这个问题。你的建议让我找到了解决方案。你是说这会推翻我愚蠢的错误,还是阻止我犯下错误的行为?
Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (found suitable version "3.4", minimum required is "3.4")