Qt5 - Link pHash庫“未定義引用”

[英]Qt5 - Link pHash library “undefined reference”


I would like to add an external library called pHash. I added this to .pro file :

我想添加一個外部庫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

But no one function of the library is working. When I try to use one, I have build error "undefined reference to pHashFunction". There is an example of use :

但是這個圖書館的一個功能沒有發揮作用。當我嘗試使用一個時,我有一個構建錯誤“未定義的pHashFunction引用”。有一個使用的例子:

#include "myclass.h"

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

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

Then there is the build log :

然后是構建日志:

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

Thank you in advance for your help :)

感謝您的幫助:

2 个解决方案

#1


1  

try to add the .c and .cpp to your project(dirent.c,ph_fft.c, pHash.cpp,phcomplex.c) it worked on my pc, but I think the issue is that the .dll and .lib are not compatible with your Qt version, cause it's compiled with Visual studio.

嘗試將.c和.cpp添加到項目中(dirent.c,ph_fft)。c, phash。cpp,phcomplex.c)它在我的電腦上工作,但是我認為問題是。dll和。lib與你的Qt版本不兼容,因為它是用Visual studio編譯的。

#2


1  

The library pHash is no longer supported and there are many problems.

庫pHash不再被支持,並且存在許多問題。

  1. The compiler MinGW 4.9.2 used by Qt is not compatible with .dll files built in MSVC.

    Qt使用的編譯器MinGW 4.9.2與MSVC中構建的.dll文件不兼容。

  2. It is not enough to use the trick "MSVC and MinGW DLLs", since the function ph_about() is not exported from pHash.dll, for example Building the pHash library on Windows

    使用“MSVC和MinGW dll”這個技巧是不夠的,因為ph_about()函數不是從pHash導出的。例如,在Windows上構建pHash庫

  3. It is possible to integrate all pHash files into Qt project, so the library can be built together with the application. Since the library project is prepared for Visual Studio I would say that the Qt should also be based on VC. However, the library pHash is old. It was written for Visual Studio 2008. Now it gives error on deprecated Windows function SHGetSpecialFolderPathA.

    可以將所有pHash文件集成到Qt項目中,這樣就可以將庫與應用程序一起構建。由於庫項目是為Visual Studio准備的,我認為Qt也應該基於VC。然而,圖書館的傳統已經過時了。它是為Visual Studio 2008編寫的。現在它在已廢棄的Windows函數SHGetSpecialFolderPathA上出錯。

  4. It is still prossible to compile everything using Qt MinGW 4.9.2 compiler. In that case it is needed to add DEFINES += HAVE_IMAGE_HASH=1 to the project .pro file to enable that macro also for pHash compilation. However, to use native support for images the libraries libjpeg and libpng also should be compiled with the same compiler, for example Compiling libjpeg If the image libraries are not used, Cimg tries to run some external executable gm.exe (probably from GraphicsMagick).

    使用Qt MinGW 4.9.2編譯器編譯所有內容仍然是可能的。在這種情況下,需要將define += HAVE_IMAGE_HASH=1添加到項目.pro文件中,以使該宏也能用於pHash編譯。然而,為了對圖像使用本機支持,libjpeg和libpng也應該使用相同的編譯器進行編譯,例如,如果不使用映像庫,則編譯libjpeg, Cimg嘗試運行一些外部可執行的gm.exe(可能來自GraphicsMagick)。

If the library is needed for some quick task it is possible to consider virtual Linux, since here it can be used out of the box https://stackoverflow.com/a/33002746/4023446

如果需要一些快速任務的庫,那么可以考慮使用虛擬Linux,因為這里可以使用box https://stackoverflow.com/a/33002746/4023446。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/10/07/725f9327fe99035798350f2143a90177.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com