QMake在指定的文件夹中找到库但是链接器没有

时间:2016-07-15 11:26:49

标签: c++ qt dll linker qmake

项目的状态

我正在尝试将QVTKWidget集成到qmake Qt 5.7项目中,从而为我的应用程序提供了对3D曲面图表的一些很好的支持(2D图表功能目前由{{ 1}}但如果我发现它很容易集成,我可能会切换到VTK的2D图表模块。

到目前为止已完成的工作

我已经在调试版和发行版中成功构建了VTK工具包(分别在QwtC:\VTK提供。除此之外,我还成功设法在我的{{{}}中放置了一些VTK内容{1}}通过手动指定包含哪些DLL库。

问题

标题中提到的问题出现在我使用C:\VTKDebug\的函数QWidgetqmakefiles()检索所有共享库时,具体取决于构建类型项目。原因是根据我在我的应用程序中包含的内容,我可能需要手动指定3-4或20-30个VTK库。为了创建一个原型,这是一个非常体力劳动的工作,我想跳过那个部分,稍后再处理它,我会评估VTK是否适合我的需求。 VTK中提供的C:\VTK\bin模块提供此功能,因此您可以根据需要直接链接到C:\VTKDebug\bin。目前我不知道对cmake项目的开箱即用支持。

这是我的${VTK_LIBRARIES}文件:

qmake

当我执行pro时,我在Qt Creator中看到以下消息(使用Qt 5.7 SDK,MinGW 5.3在64位Windows 10系统上全部为32位):

QT       += core gui    
CONFIG   += c++11

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Demo
TEMPLATE = app

RESOURCES = resources.qrc

# Variables will store the path to the root directory of each library using the information provided by the respective system environment variables.
MHCP_API = ""
QWT_API = ""
VTK_API = ""

CONFIG(debug, debug|release) {
    message(Application will be built in DEBUG mode)
    MHCP_API = $$(MCHP_HMI_API_PATH) # TODO Compile the library for debug releases (requires Visual C++)
    QWT_API = $$(QWT_PATH) # QWT on my system is compiled in debug_and_release mode which means that both versios of the library are located at the same location (different names though!)
    VTK_API = $$(VTK_PATH_DEBUG)
    LIBS += -L$$QWT_API\\lib -lqwtd \
            -L$$MHCP_API\\lib -lmchp_hmid
}
else {
    message(Application will be built in RELEASE mode)
    MHCP_API = $$(MCHP_HMI_API_PATH)
    QWT_API = $$(QWT_PATH)
    VTK_API = $$(VTK_PATH)
    LIBS += -L$$QWT_API\\lib -lqwt \
            -L$$MHCP_API\\lib -lmchp_hmi
}

message(-----------------------------------------------------------------------------------------)

isEmpty(MHCP_API) { error(MHCP_API variable is empty. Please make sure that MCHP_HMI_API_PATH system variable is set and that you have both reading and writing access to it) }
else { message(MHCP_API root folder set to $$MHCP_API) }

isEmpty(QWT_API) { error(QWT_API variable is empty. Please make sure that QWT system variable is set and that you have reading access to it) }
else { message(QWT_API root folder set to $$QWT_API) }

isEmpty(VTK_API) { error(VTK_API variable is empty. Please make sure that VTK system variable is set and that you have reading access to it) }
else { message(VTK_API root folder set to $$VTK_API) }

message(-----------------------------------------------------------------------------------------)

DEFINES += "VTK_DEFINITIONS"

#LIBS     += -L$$VTK_API\\lib -lvtkRenderingCore-7.0 -lvtkRenderingOpenGL2-7.0 -lvtkCommonExecutionModel-7.0 -lvtkCommonCore-7.0 -lvtkViewsQt-7.0 -lvtkGUISupportQt-7.0 -lvtkRenderingQt-7.0 -lvtkChartsCore-7.0 -lvtkFiltersSources-7.0 #-lvtkRenderingOpenGL2-7.0 #FilterSources is required for the SphereSource example

LIBS    += -L$$VTK_API\\bin
VTK_API_SHARED_LIB_FILES = $$files($$VTK_API\\bin\\*.dll)
for(FILE, VTK_API_SHARED_LIB_FILES) {
    BASENAME = $$basename(FILE)
    NO_PREFIX_NAME = $$replace(BASENAME, lib,)
    VTK_LIB = $$replace(NO_PREFIX_NAME, .dll,)
    message(Found "$$VTK_LIB")
    LIBS += -l$$VTK_LIB
}

message(-----------------------------------------------------------------------------------------)
message(Appending $$LIBS)

INCLUDEPATH += $$MHCP_API\\include \
               $$QWT_API\\include \
               $$VTK_API\\include\\vtk-7.0


HEADERS  += device_api.h \
    device_api_dynamic.h \
    demo.h \
    device.h \
    misc.h \
    device_plot.h

SOURCES  += main.cpp\
    demo.cpp \
    device.cpp \
    device_plot.cpp

FORMS    += demo.ui

RESOURCES += \
    resources.qrc

到目前为止,这么好。如上所述,事情在链接阶段失败,即我得到以下错误

qmake

即使我可以在Project MESSAGE: Application will be built in DEBUG mode Project MESSAGE: ----------------------------------------------------------------------------------------- Project MESSAGE: MHCP_API root folder set to C:\Program Files (x86)\Device\api Project MESSAGE: QWT_API root folder set to C:\Qwt-6.1.3 Project MESSAGE: VTK_API root folder set to C:\VTKDebug Project MESSAGE: ----------------------------------------------------------------------------------------- Project MESSAGE: Found vtkalg-7.0 Project MESSAGE: Found vtkChartsCore-7.0 Project MESSAGE: Found vtkCommonColor-7.0 Project MESSAGE: Found vtkCommonComputationalGeometry-7.0 Project MESSAGE: Found vtkCommonCore-7.0 Project MESSAGE: Found vtkCommonDataModel-7.0 Project MESSAGE: Found vtkCommonExecutionModel-7.0 Project MESSAGE: Found vtkCommonMath-7.0 Project MESSAGE: Found vtkCommonMisc-7.0 Project MESSAGE: Found vtkCommonSystem-7.0 Project MESSAGE: Found vtkCommonTransforms-7.0 Project MESSAGE: Found vtkDICOMParser-7.0 Project MESSAGE: Found vtkDomainsChemistry-7.0 Project MESSAGE: Found vtkDomainsChemistryOpenGL2-7.0 Project MESSAGE: Found vtkexoIIc-7.0 Project MESSAGE: Found vtkexpat-7.0 Project MESSAGE: Found vtkFiltersAMR-7.0 Project MESSAGE: Found vtkFiltersCore-7.0 Project MESSAGE: Found vtkFiltersExtraction-7.0 Project MESSAGE: Found vtkFiltersFlowPaths-7.0 Project MESSAGE: Found vtkFiltersGeneral-7.0 Project MESSAGE: Found vtkFiltersGeneric-7.0 Project MESSAGE: Found vtkFiltersGeometry-7.0 Project MESSAGE: Found vtkFiltersHybrid-7.0 Project MESSAGE: Found vtkFiltersHyperTree-7.0 Project MESSAGE: Found vtkFiltersImaging-7.0 Project MESSAGE: Found vtkFiltersModeling-7.0 Project MESSAGE: Found vtkFiltersParallel-7.0 Project MESSAGE: Found vtkFiltersParallelImaging-7.0 Project MESSAGE: Found vtkFiltersProgrammable-7.0 Project MESSAGE: Found vtkFiltersSelection-7.0 Project MESSAGE: Found vtkFiltersSMP-7.0 Project MESSAGE: Found vtkFiltersSources-7.0 Project MESSAGE: Found vtkFiltersStatistics-7.0 Project MESSAGE: Found vtkFiltersTexture-7.0 Project MESSAGE: Found vtkFiltersVerdict-7.0 Project MESSAGE: Found vtkfreetype-7.0 Project MESSAGE: Found vtkGeovisCore-7.0 Project MESSAGE: Found vtkglew-7.0 Project MESSAGE: Found vtkGUISupportQt-7.0 Project MESSAGE: Found vtkGUISupportQtSQL-7.0 Project MESSAGE: Found vtkImagingColor-7.0 Project MESSAGE: Found vtkImagingCore-7.0 Project MESSAGE: Found vtkImagingFourier-7.0 Project MESSAGE: Found vtkImagingGeneral-7.0 Project MESSAGE: Found vtkImagingHybrid-7.0 Project MESSAGE: Found vtkImagingMath-7.0 Project MESSAGE: Found vtkImagingMorphological-7.0 Project MESSAGE: Found vtkImagingSources-7.0 Project MESSAGE: Found vtkImagingStatistics-7.0 Project MESSAGE: Found vtkImagingStencil-7.0 Project MESSAGE: Found vtkInfovisCore-7.0 Project MESSAGE: Found vtkInfovisLayout-7.0 Project MESSAGE: Found vtkInteractionImage-7.0 Project MESSAGE: Found vtkInteractionStyle-7.0 Project MESSAGE: Found vtkInteractionWidgets-7.0 Project MESSAGE: Found vtkIOAMR-7.0 Project MESSAGE: Found vtkIOCore-7.0 Project MESSAGE: Found vtkIOEnSight-7.0 Project MESSAGE: Found vtkIOExodus-7.0 Project MESSAGE: Found vtkIOExport-7.0 Project MESSAGE: Found vtkIOGeometry-7.0 Project MESSAGE: Found vtkIOImage-7.0 Project MESSAGE: Found vtkIOImport-7.0 Project MESSAGE: Found vtkIOInfovis-7.0 Project MESSAGE: Found vtkIOLegacy-7.0 Project MESSAGE: Found vtkIOLSDyna-7.0 Project MESSAGE: Found vtkIOMINC-7.0 Project MESSAGE: Found vtkIOMovie-7.0 Project MESSAGE: Found vtkIONetCDF-7.0 Project MESSAGE: Found vtkIOParallel-7.0 Project MESSAGE: Found vtkIOParallelXML-7.0 Project MESSAGE: Found vtkIOPLY-7.0 Project MESSAGE: Found vtkIOSQL-7.0 Project MESSAGE: Found vtkIOVideo-7.0 Project MESSAGE: Found vtkIOXML-7.0 Project MESSAGE: Found vtkIOXMLParser-7.0 Project MESSAGE: Found vtkjpeg-7.0 Project MESSAGE: Found vtkjsoncpp-7.0 Project MESSAGE: Found vtkxml2-7.0 Project MESSAGE: Found vtkmetaio-7.0 Project MESSAGE: Found vtkNetCDF-7.0 Project MESSAGE: Found vtkNetCDF_cxx-7.0 Project MESSAGE: Found vtkoggtheora-7.0 Project MESSAGE: Found vtkParallelCore-7.0 Project MESSAGE: Found vtkpng-7.0 Project MESSAGE: Found vtkproj4-7.0 Project MESSAGE: Found vtkRenderingAnnotation-7.0 Project MESSAGE: Found vtkRenderingContext2D-7.0 Project MESSAGE: Found vtkRenderingContextOpenGL2-7.0 Project MESSAGE: Found vtkRenderingCore-7.0 Project MESSAGE: Found vtkRenderingFreeType-7.0 Project MESSAGE: Found vtkRenderingImage-7.0 Project MESSAGE: Found vtkRenderingLabel-7.0 Project MESSAGE: Found vtkRenderingLOD-7.0 Project MESSAGE: Found vtkRenderingOpenGL2-7.0 Project MESSAGE: Found vtkRenderingQt-7.0 Project MESSAGE: Found vtkRenderingVolume-7.0 Project MESSAGE: Found vtkRenderingVolumeOpenGL2-7.0 Project MESSAGE: Found vtksys-7.0 Project MESSAGE: Found vtkTestingGenericBridge-7.0 Project MESSAGE: Found vtkTestingIOSQL-7.0 Project MESSAGE: Found vtkTestingRendering-7.0 Project MESSAGE: Found vtktiff-7.0 Project MESSAGE: Found vtkverdict-7.0 Project MESSAGE: Found vtkViewsContext2D-7.0 Project MESSAGE: Found vtkViewsCore-7.0 Project MESSAGE: Found vtkViewsInfovis-7.0 Project MESSAGE: Found vtkViewsQt-7.0 Project MESSAGE: Found vtkz-7.0 Project MESSAGE: Found vtkhdf5-7.0 Project MESSAGE: Found vtkhdf5_hl-7.0 Project MESSAGE: ----------------------------------------------------------------------------------------- Project MESSAGE: Appending -LC:\Qwt-6.1.3\lib -lqwtd -LC:\Program Files (x86)\Device\api\lib -ldevice_apid -LC:\VTKDebug\bin -lvtkalg-7.0 -lvtkChartsCore-7.0 -lvtkCommonColor-7.0 -lvtkCommonComputationalGeometry-7.0 -lvtkCommonCore-7.0 -lvtkCommonDataModel-7.0 -lvtkCommonExecutionModel-7.0 -lvtkCommonMath-7.0 -lvtkCommonMisc-7.0 -lvtkCommonSystem-7.0 -lvtkCommonTransforms-7.0 -lvtkDICOMParser-7.0 -lvtkDomainsChemistry-7.0 -lvtkDomainsChemistryOpenGL2-7.0 -lvtkexoIIc-7.0 -lvtkexpat-7.0 -lvtkFiltersAMR-7.0 -lvtkFiltersCore-7.0 -lvtkFiltersExtraction-7.0 -lvtkFiltersFlowPaths-7.0 -lvtkFiltersGeneral-7.0 -lvtkFiltersGeneric-7.0 -lvtkFiltersGeometry-7.0 -lvtkFiltersHybrid-7.0 -lvtkFiltersHyperTree-7.0 -lvtkFiltersImaging-7.0 -lvtkFiltersModeling-7.0 -lvtkFiltersParallel-7.0 -lvtkFiltersParallelImaging-7.0 -lvtkFiltersProgrammable-7.0 -lvtkFiltersSelection-7.0 -lvtkFiltersSMP-7.0 -lvtkFiltersSources-7.0 -lvtkFiltersStatistics-7.0 -lvtkFiltersTexture-7.0 -lvtkFiltersVerdict-7.0 -lvtkfreetype-7.0 -lvtkGeovisCore-7.0 -lvtkglew-7.0 -lvtkGUISupportQt-7.0 -lvtkGUISupportQtSQL-7.0 -lvtkImagingColor-7.0 -lvtkImagingCore-7.0 -lvtkImagingFourier-7.0 -lvtkImagingGeneral-7.0 -lvtkImagingHybrid-7.0 -lvtkImagingMath-7.0 -lvtkImagingMorphological-7.0 -lvtkImagingSources-7.0 -lvtkImagingStatistics-7.0 -lvtkImagingStencil-7.0 -lvtkInfovisCore-7.0 -lvtkInfovisLayout-7.0 -lvtkInteractionImage-7.0 -lvtkInteractionStyle-7.0 -lvtkInteractionWidgets-7.0 -lvtkIOAMR-7.0 -lvtkIOCore-7.0 -lvtkIOEnSight-7.0 -lvtkIOExodus-7.0 -lvtkIOExport-7.0 -lvtkIOGeometry-7.0 -lvtkIOImage-7.0 -lvtkIOImport-7.0 -lvtkIOInfovis-7.0 -lvtkIOLegacy-7.0 -lvtkIOLSDyna-7.0 -lvtkIOMINC-7.0 -lvtkIOMovie-7.0 -lvtkIONetCDF-7.0 -lvtkIOParallel-7.0 -lvtkIOParallelXML-7.0 -lvtkIOPLY-7.0 -lvtkIOSQL-7.0 -lvtkIOVideo-7.0 -lvtkIOXML-7.0 -lvtkIOXMLParser-7.0 -lvtkjpeg-7.0 -lvtkjsoncpp-7.0 -lvtkxml2-7.0 -lvtkmetaio-7.0 -lvtkNetCDF-7.0 -lvtkNetCDF_cxx-7.0 -lvtkoggtheora-7.0 -lvtkParallelCore-7.0 -lvtkpng-7.0 -lvtkproj4-7.0 -lvtkRenderingAnnotation-7.0 -lvtkRenderingContext2D-7.0 -lvtkRenderingContextOpenGL2-7.0 -lvtkRenderingCore-7.0 -lvtkRenderingFreeType-7.0 -lvtkRenderingImage-7.0 -lvtkRenderingLabel-7.0 -lvtkRenderingLOD-7.0 -lvtkRenderingOpenGL2-7.0 -lvtkRenderingQt-7.0 -lvtkRenderingVolume-7.0 -lvtkRenderingVolumeOpenGL2-7.0 -lvtksys-7.0 -lvtkTestingGenericBridge-7.0 -lvtkTestingIOSQL-7.0 -lvtkTestingRendering-7.0 -lvtktiff-7.0 -lvtkverdict-7.0 -lvtkViewsContext2D-7.0 -lvtkViewsCore-7.0 -lvtkViewsInfovis-7.0 -lvtkViewsQt-7.0 -lvtkz-7.0 -lvtkhdf5-7.0 -lvtkhdf5_hl-7.0 的输出中清楚地看到它们:

cannot find -lvtkalg-7.0
cannot find -lvtkxml2-7.0
cannot find -lvtkz-7.0

我怀疑这实际上与VTK本身有什么关系,而是与我的项目结构有关。

编辑:我发现了为什么但不知道如何修复它。基本上,所提到的文件具有命名对齐qmake。因此,当我Project MESSAGE: Appending -LC:\Qwt-6.1.3\lib -lqwtd -LC:\Program Files (x86)\Device\api\lib -ldevice_apid -LC:\VTKDebug\bin -lvtkalg-7.0 ... -lvtkxml2-7.0 .. -lvtkz-7.0 删除libvtkNAMElib-7.0个子串时,会留下$$replace(BASENAME, lib,)不存在的lib。我在浏览器中查看提到的DLL文件时发现了这一点并注意到这种麻烦。我现在正在寻找一种方法来只替换第一次出现的子串

PS:我对如何根据文件结构管理VTK工具包感到非常不满。库文件的命名约定对开发人员来说似乎并不重要(此评论没有任何违法行为)。 : - /

1 个答案:

答案 0 :(得分:0)

好的,问题解决了。正如我在问题末尾的 EDIT 部分中提到的,问题在于VTK开发人员选择的奇怪命名约定以及三个事实(至少我的构建并不是所有功能)已启用)这些库不符合其余库。

导致问题的库是

libvtkalglib-7.0
libvtkxml2lib-7.0
libvtkzlib-7.0

,其余的遵循命名架构

libvtkXXX-7.0

我的一位同事注意到所有文件都以libvtk*而非lib开头的模式。如果将replace()的正则表达式模式编辑为

NO_PREFIX_NAME = $$replace(BASENAME, libvtk, vtk)

我得到了所需的结果,因为只有lib也涵盖*lib*libvtk涵盖*libvtk*,这意味着*lib-7.0不属于匹配。

这是最终的DLL文件抓取循环,为那些想要它的人:

LIBS    += -L$$VTK_API\\bin
VTK_API_SHARED_LIB_FILES = $$files($$VTK_API\\bin\\*.dll)
for(FILE, VTK_API_SHARED_LIB_FILES) {
    BASENAME = $$basename(FILE)
    NO_PREFIX_NAME = $$replace(BASENAME, libvtk, vtk) # 3 of the VTK libs have the naming convention libvtkXXXlib-7.0 instead of libvtkXXX-7.0
    VTK_LIB = $$replace(NO_PREFIX_NAME, .dll,)
    message(Found "$$VTK_LIB")
    LIBS += -l$$VTK_LIB
}