0

我想添加一个名为pHash的外部库。我将此添加到 .pro 文件中:

win32:CONFIG(release, debug|release): LIBS += -L$PWD/Libs/pHash-0.9.4/release -lpHash
else:win32:CONFIG(debug, debug|release): LIBS += -L$PWD/Libs/pHash-0.9.4/debug -lpHash

INCLUDEPATH += $PWD/Libs/pHash-0.9.4
DEPENDPATH += $PWD/Libs/pHash-0.9.4

win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $PWD/Libs/pHash-0.9.4/release/pHash.lib
else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $PWD/Libs/pHash-0.9.4/debug/pHash.lib

但是图书馆的任何一项功能都没有工作。当我尝试使用一个时,我构建了错误“未定义对 pHashFunction 的引用”。有一个使用示例:

#include "myclass.h"

#define HAVE_IMAGE_HASH 1 // config
#include "pHash.h"

void MyClass::perform() {
    const char *msg = ph_about();
    qDebug() << msg;
}

然后是构建日志:

C:/Qt/Tools/mingw492_32/bin/mingw32-make -f Makefile.Debug clean
mingw32-make[1]: Entering directory 'C:/Users/vi/Documents/Programmation/QtWorkspace/build-myProject-Desktop_Qt_5_5_0_MinGW_32bit-Debug'
rm -f debug/qrc_qml.cpp
rm -f debug/moc_myclass.cpp
rm -f debug/main.o debug/myclass.o debug/qrc_qml.o debug/moc_myclass.o
mingw32-make[1]: Leaving directory 'C:/Users/vi/Documents/Programmation/QtWorkspace/build-myProject-Desktop_Qt_5_5_0_MinGW_32bit-Debug'
C:/Qt/Tools/mingw492_32/bin/mingw32-make -f Makefile.Release clean
mingw32-make[1]: Entering directory 'C:/Users/vi/Documents/Programmation/QtWorkspace/build-myProject-Desktop_Qt_5_5_0_MinGW_32bit-Debug'
rm -f release/qrc_qml.cpp
rm -f release/moc_myclass.cpp
rm -f release/main.o release/myclass.o release/qrc_qml.o release/moc_myclass.o
mingw32-make[1]: Leaving directory 'C:/Users/vi/Documents/Programmation/QtWorkspace/build-myProject-Desktop_Qt_5_5_0_MinGW_32bit-Debug'
01:31:34: Le processus "C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe" s'est terminé normalement.
01:31:34: Configuration inchangée, étape qmake sautée.
01:31:34: Débute : "C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe" 
C:/Qt/Tools/mingw492_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/vi/Documents/Programmation/QtWorkspace/build-myProject-Desktop_Qt_5_5_0_MinGW_32bit-Debug'
g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../myProject -I. -I../myProject/Libs/pHash-0.9.4 -IC:/Qt/5.5/mingw492_32/include -IC:/Qt/5.5/mingw492_32/include/QtQuick -IC:/Qt/5.5/mingw492_32/include/QtGui -IC:/Qt/5.5/mingw492_32/include/QtANGLE -IC:/Qt/5.5/mingw492_32/include/QtQml -IC:/Qt/5.5/mingw492_32/include/QtNetwork -IC:/Qt/5.5/mingw492_32/include/QtCore -Idebug -IC:/Qt/5.5/mingw492_32/mkspecs/win32-g++  -o debug/main.o ../myProject/main.cpp
g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../myProject -I. -I../myProject/Libs/pHash-0.9.4 -IC:/Qt/5.5/mingw492_32/include -IC:/Qt/5.5/mingw492_32/include/QtQuick -IC:/Qt/5.5/mingw492_32/include/QtGui -IC:/Qt/5.5/mingw492_32/include/QtANGLE -IC:/Qt/5.5/mingw492_32/include/QtQml -IC:/Qt/5.5/mingw492_32/include/QtNetwork -IC:/Qt/5.5/mingw492_32/include/QtCore -Idebug -IC:/Qt/5.5/mingw492_32/mkspecs/win32-g++  -o debug/myclass.o ../myProject/myclass.cpp
In file included from ../myProject/myclass.cpp:3:0:
../myProject/Libs/pHash-0.9.4/pHash.h:299:21: warning: 'cimg_library::CImg<float>* ph_dct_matrix(int)' declared 'static' but never defined [-Wunused-function]
 static CImg<float>* ph_dct_matrix(const int N);
                     ^
'C:\Qt\5.5\mingw492_32\bin\rcc.exe' -name qml ../myProject/qml.qrc -o debug/qrc_qml.cpp
g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../myProject -I. -I../myProject/Libs/pHash-0.9.4 -IC:/Qt/5.5/mingw492_32/include -IC:/Qt/5.5/mingw492_32/include/QtQuick -IC:/Qt/5.5/mingw492_32/include/QtGui -IC:/Qt/5.5/mingw492_32/include/QtANGLE -IC:/Qt/5.5/mingw492_32/include/QtQml -IC:/Qt/5.5/mingw492_32/include/QtNetwork -IC:/Qt/5.5/mingw492_32/include/QtCore -Idebug -IC:/Qt/5.5/mingw492_32/mkspecs/win32-g++  -o debug/qrc_qml.o debug/qrc_qml.cpp
'C:\Qt\5.5\mingw492_32\bin\moc.exe' -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -D__GNUC__ -DWIN32 -IC:/Qt/5.5/mingw492_32/mkspecs/win32-g++ -IC:/Users/vi/Documents/Programmation/QtWorkspace/myProject -IC:/Users/vi/Documents/Programmation/QtWorkspace/myProject/Libs/pHash-0.9.4 -IC:/Qt/5.5/mingw492_32/include -IC:/Qt/5.5/mingw492_32/include/QtQuick -IC:/Qt/5.5/mingw492_32/include/QtGui -IC:/Qt/5.5/mingw492_32/include/QtANGLE -IC:/Qt/5.5/mingw492_32/include/QtQml -IC:/Qt/5.5/mingw492_32/include/QtNetwork -IC:/Qt/5.5/mingw492_32/include/QtCore -I. ../myProject/myclass.h -o debug/moc_myclass.cpp
g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../myProject -I. -I../myProject/Libs/pHash-0.9.4 -IC:/Qt/5.5/mingw492_32/include -IC:/Qt/5.5/mingw492_32/include/QtQuick -IC:/Qt/5.5/mingw492_32/include/QtGui -IC:/Qt/5.5/mingw492_32/include/QtANGLE -IC:/Qt/5.5/mingw492_32/include/QtQml -IC:/Qt/5.5/mingw492_32/include/QtNetwork -IC:/Qt/5.5/mingw492_32/include/QtCore -Idebug -IC:/Qt/5.5/mingw492_32/mkspecs/win32-g++  -o debug/moc_myclass.o debug/moc_myclass.cpp
g++ -Wl,-subsystem,windows -mthreads -o debug/myProject.exe debug/main.o debug/myclass.o debug/qrc_qml.o debug/moc_myclass.o  -lmingw32 -LC:/Qt/5.5/mingw492_32/lib -lqtmaind -lshell32 -LC:/Users/vi/Documents/Programmation/QtWorkspace/myProject/Libs/pHash-0.9.4/debug -lpHash -lQt5Quickd -lQt5Guid -lQt5Qmld -lQt5Networkd -lQt5Cored 
debug/myclass.o: In function `ZN6myclass7performEv':
C:\Users\vi\Documents\Programmation\QtWorkspace\build-myProject-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../myProject/myclass.cpp:11: undefined reference to `ph_about'
collect2.exe: error: ld returned 1 exit status
Makefile.Debug:83: recipe for target 'debug/myProject.exe' failed
mingw32-make[1]: *** [debug/myProject.exe] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/vi/Documents/Programmation/QtWorkspace/build-myProject-Desktop_Qt_5_5_0_MinGW_32bit-Debug'
makefile:34: recipe for target 'debug' failed
mingw32-make: *** [debug] Error 2

预先感谢您的帮助 :)

4

2 回答 2

1

尝试将 .c 和 .cpp 添加到您的项目(dirent.c、ph_fft.c、pHash.cpp、phcomplex.c)它在我的电脑上工作,但我认为问题是 .dll 和 .lib 不是与您的 Qt 版本兼容,因为它是使用 Visual Studio 编译的。

于 2015-10-07T19:53:33.597 回答
1

不再支持库 pHash 并且存在很多问题。

  1. .dllQt 使用的编译器 MinGW 4.9.2 与MSVC 中内置的文件不兼容。

  2. 使用技巧“MSVC and MinGW DLLs”是不够的,因为函数ph_about()不是从 导出的pHash.dll,例如在 Windows 上构建 pHash 库

  3. 可以将所有 pHash 文件集成到 Qt 项目中,因此该库可以与应用程序一起构建。由于库项目是为 Visual Studio 准备的,我想说 Qt 也应该基于 VC。但是,图书馆 pHash 是旧的。它是为 Visual Studio 2008 编写的。现在它在 deprecated Windows function 上给出错误SHGetSpecialFolderPathA

  4. 仍然可以使用 Qt MinGW 4.9.2 编译器编译所有内容。在这种情况下,需要添加DEFINES += HAVE_IMAGE_HASH=1到项目.pro文件中以启用该宏以进行pHash编译。但是,要使用对图像的本机支持,库libjpeglibpng应该使用相同的编译器进行编译,例如编译 libjpeg 如果不使用图像库,Cimg请尝试运行一些外部可执行文件gm.exe(可能来自 GraphicsMagick)。

如果某些快速任务需要该库,则可以考虑使用虚拟 Linux,因为在这里它可以开箱即用https://stackoverflow.com/a/33002746/4023446

于 2015-10-07T22:54:49.777 回答