带有 QT 的 ITK:metadataobject.cxx 中的未定义引用 vnl_vector

ITK with QT: undefined reference vnl_vector in metadataobject.cxx

我正在尝试编译一个使用 ITK 的 Qt 项目,但我收到来自 ITK 库的 linker 错误(见下文)。我在 运行 Ubuntu 16.04 上使用 Qt 5.9.1 进行构建。我编译了 ITK 版本 4.12.1,但我也尝试了 4.13 以及同事提供的预构建版本 4.12.2。我曾尝试使用 CMake 3.5 进行编译,后来又使用 CMake 3.10 进行编译,但对于所有这些组合,我都遇到了相同的错误。

我在 ITK 构建的 lib 文件夹中使用命令 lorder * | tsort 生成了包含在我的 Qt 项目中的库列表。这应该会生成包含库的正确顺序,对吗?

编译器抱怨找不到 vnl_vector,但我检查了 linked 库的列表,-litkvnl 以及 -litkvnl_algo 都在里面和上面-lITKCommon 这似乎是问题所在。

下面我向库提供了编译错误以及我在其中 link 的 .pri 文件。任何帮助将不胜感激!

错误信息:

//usr/local/lib/libITKCommon-4.12.a(itkMetaDataObject.cxx.o): In function `itk::MetaDataObject<itk::Array<char> >::~MetaDataObject()':
itkMetaDataObject.cxx:(.text._ZN3itk14MetaDataObjectINS_5ArrayIcEEED2Ev[_ZN3itk14MetaDataObjectINS_5ArrayIcEEED5Ev]+0x2a): undefined reference to `vnl_vector<char>::~vnl_vector()'
//usr/local/lib/libITKCommon-4.12.a(itkMetaDataObject.cxx.o): In function `itk::MetaDataObject<itk::Array<int> >::~MetaDataObject()':
itkMetaDataObject.cxx:(.text._ZN3itk14MetaDataObjectINS_5ArrayIiEEED2Ev[_ZN3itk14MetaDataObjectINS_5ArrayIiEEED5Ev]+0x2a): undefined reference to `vnl_vector<int>::~vnl_vector()'
Makefile:249: recipe for target 'mesh2binary' failed
//usr/local/lib/libITKCommon-4.12.a(itkMetaDataObject.cxx.o): In function `itk::MetaDataObject<itk::Array<float> >::~MetaDataObject()':
itkMetaDataObject.cxx:(.text._ZN3itk14MetaDataObjectINS_5ArrayIfEEED2Ev[_ZN3itk14MetaDataObjectINS_5ArrayIfEEED5Ev]+0x2a): undefined reference to `vnl_vector<float>::~vnl_vector()'
//usr/local/lib/libITKCommon-4.12.a(itkMetaDataObject.cxx.o): In function `itk::MetaDataObject<itk::Array<char> >::SetMetaDataObjectValue(itk::Array<char> const&)':
itkMetaDataObject.cxx:(.text._ZN3itk14MetaDataObjectINS_5ArrayIcEEE22SetMetaDataObjectValueERKS2_[_ZN3itk14MetaDataObjectINS_5ArrayIcEEE22SetMetaDataObjectValueERKS2_]+0x26): undefined reference to `vnl_vector<char>::set_size(unsigned long)'
itkMetaDataObject.cxx:(.text._ZN3itk14MetaDataObjectINS_5ArrayIcEEE22SetMetaDataObjectValueERKS2_[_ZN3itk14MetaDataObjectINS_5ArrayIcEEE22SetMetaDataObjectValueERKS2_]+0x39): undefined reference to `vnl_vector<char>::operator=(vnl_vector<char> const&)'
//usr/local/lib/libITKCommon-4.12.a(itkMetaDataObject.cxx.o): In function `itk::MetaDataObject<itk::Array<int> >::SetMetaDataObjectValue(itk::Array<int> const&)':
itkMetaDataObject.cxx:(.text._ZN3itk14MetaDataObjectINS_5ArrayIiEEE22SetMetaDataObjectValueERKS2_[_ZN3itk14MetaDataObjectINS_5ArrayIiEEE22SetMetaDataObjectValueERKS2_]+0x26): undefined reference to `vnl_vector<int>::set_size(unsigned long)'
itkMetaDataObject.cxx:(.text._ZN3itk14MetaDataObjectINS_5ArrayIiEEE22SetMetaDataObjectValueERKS2_[_ZN3itk14MetaDataObjectINS_5ArrayIiEEE22SetMetaDataObjectValueERKS2_]+0x39): undefined reference to `vnl_vector<int>::operator=(vnl_vector<int> const&)'
//usr/local/lib/libITKCommon-4.12.a(itkMetaDataObject.cxx.o): In function `itk::MetaDataObject<itk::Array<float> >::SetMetaDataObjectValue(itk::Array<float> const&)':
itkMetaDataObject.cxx:(.text._ZN3itk14MetaDataObjectINS_5ArrayIfEEE22SetMetaDataObjectValueERKS2_[_ZN3itk14MetaDataObjectINS_5ArrayIfEEE22SetMetaDataObjectValueERKS2_]+0x26): undefined reference to `vnl_vector<float>::set_size(unsigned long)'
itkMetaDataObject.cxx:(.text._ZN3itk14MetaDataObjectINS_5ArrayIfEEE22SetMetaDataObjectValueERKS2_[_ZN3itk14MetaDataObjectINS_5ArrayIfEEE22SetMetaDataObjectValueERKS2_]+0x39): undefined reference to `vnl_vector<float>::operator=(vnl_vector<float> const&)'
collect2: error: ld returned 1 exit status
make: *** [mesh2binary] Error 1
11:24:11: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project mesh2binary (kit: Desktop Qt 5.9.1 GCC 64bit2)
When executing step "Make"

.pri 文件,我将其包含在我的 .pro 文件中:

ITKDIR=/usr/local/ITK/InsightToolkit-4.12.1-Release/include/ITK-4.12
ITKLIB=/usr/local/ITK/InsightToolkit-4.12.1-Release/build/lib


VERSIONNUMBER=4.12

#Include ITK Headers
INCLUDEPATH += $${ITKDIR}

# ITK Libs
LIBS += -L$${ITKLIB} -lITKBiasCorrection-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKBioCell-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKDICOMParser-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKFEM-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOBMP-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOBioRad-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOCSV-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOGDCM-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOGE-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOGIPL-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOHDF5-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOJPEG-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOLSM-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOMRC-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOMesh-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOMeta-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIONIFTI-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIONRRD-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOPNG-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOSiemens-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOSpatialObjects-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOStimulate-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOTransformBase-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOTransformHDF5-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOTransformInsightLegacy-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOTransformMatlab-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOVTK-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKKLMRegionGrowing-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKLabelMap-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKMesh-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKOptimizers-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKOptimizersv4-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKPath-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKPolynomials-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKQuadEdgeMesh-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKSpatialObjects-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKStatistics-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKTransform-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKVNLInstantiation-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKVTK-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKVideoCore-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKVideoIO-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKWatersheds-$${VERSIONNUMBER}
#LIBS += -L$${ITKLIB} -lhdf5
LIBS += -L$${ITKLIB} -litkgdcmMEXD-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litknetlib-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litktestlib-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOTIFF-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKgiftiio-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKMetaIO-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKNrrdIO-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkpng-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOIPL-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOXML-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKTransformFactory-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkhdf5_cpp
LIBS += -L$${ITKLIB} -litkNetlibSlatec-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkvnl_algo-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkgdcmMSFF-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkgdcmsocketxx-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litktiff-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKniftiio-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKIOImageBase-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkhdf5
LIBS += -L$${ITKLIB} -litkvnl-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkv3p_netlib-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkgdcmDICT-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkgdcmcharls-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkgdcmuuid-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkgdcmopenjpeg-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkgdcmjpeg8-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkgdcmjpeg16-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkgdcmjpeg12-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkjpeg-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKznz-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKCommon-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkvcl-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkgdcmIOD-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litksys-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkdouble-conversion-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkgdcmDSED-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -lITKEXPAT-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkgdcmCommon-$${VERSIONNUMBER}
LIBS += -L$${ITKLIB} -litkzlib-$${VERSIONNUMBER}

我建议您将项目的构建系统转换为 CMake。我不建议使用 CMake 以外的任何其他系统构建 ITK。从2.8.10开始就很稳定了,如果你有当前版本,应该没有问题。

您的 CMakeLists.txt 文件可能与此类似:

cmake_minimum_required(VERSION 3.1)
set (CMAKE_CXX_STANDARD 11)
project(HelloWorldItkQt)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc and uic automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
# Find the Qt libraries
find_package(Qt5Gui)
find_package(Qt5Widgets)
find_package(Qt5Core)
#find and enable ITK
find_package(ITK)
include(${ITK_USE_FILE})
# Tell CMake to create the helloworld executable
add_executable(HelloWorldItkQt WIN32 mainwindow.h simpledialog.h mainwindow.cpp simpledialog.cpp main.cpp)

# Use the Widgets module from Qt 5.
target_link_libraries(HelloWorldItkQt Qt5::Widgets Qt5::Gui Qt5::Core ${ITK_LIBRARIES})

在这里您可以找到更多信息:

Qt5 and Cmake manual

Similar SO problem