我尝试在Windows上的Qt项目中使用dlib。下载后,我立即开始尝试构建我的Qt应用程序,而不构建示例。我还从GnuWin下载了静态库libpng和libjpeg。
.pro文件:
SOURCES += main.cpp\
mainwindow.cpp \
C:/Users/user/Downloads/dlib-19.0/dlib-19.0/dlib/all/source.cpp
HEADERS += mainwindow.h
INCLUDEPATH += "C:\Users\user\Downloads\dlib-19.0\dlib-19.0"
LIBS += -L"C:\Users\user\Downloads\dlib-19.0\dlib-19.0"
INCLUDEPATH += "C:\Users\user\Downloads\dlib-19.0\dlib-19.0\dlib\external\libpng"
INCLUDEPATH += "C:\Users\user\Downloads\dlib-19.0\dlib-19.0\dlib\external\libjpeg"
LIBS += -L"C:\Users\user\Downloads\jpeg-6b-4-lib\lib" -ljpeg
LIBS += -L"C:\Users\user\Downloads\libpng-1.2.37-lib\lib" -lpng
LIBS += -lwinmm -lws2_32 -luser32 -lgdi32 -lcomctl32 -limm32
QMAKE_CXXFLAGS += -std=c++11 -DDLIB_PNG_SUPPORT -DDLIB_JPEG_SUPPORT代码:
try
{
array2d<rgb_pixel> img;
load_image(img, "C:\\Users\\user\\Downloads\\test.jpg");
}
catch (exception& e)
{
cout << "\nexception thrown!" << endl;
cout << e.what() << endl;
}MinGW输出
png_loader.cpp:103:对“png_set_longjmp_fn”的未定义引用 png_loader.cpp:153:对“png_set_longjmp_fn”的未定义引用 save_png.cpp:20:对“png_set_longjmp_fn”的未定义引用 save_png.cpp:72:对“png_set_longjmp_fn”的未定义引用
我知道我需要使用libpng 1.4,但是在GnuWin中找不到这个版本,所以我使用了最相关的1.2。
MSVC运行时异常:
抛出异常! 无法在文件C:\Users\user\Downloads\test.jpg中加载图像。 您必须定义DLIB_JPEG_SUPPORT并链接到libjpeg以读取JPEG文件。 按照http://dlib.net/compile.html上的说明进行操作。 请注意,必须为整个项目定义DLIB_JPEG_SUPPORT。 所以不要在一个文件中定义它。相反,将其添加到C/C++->预处理器->预处理定义中。 字段在Visual的“属性页”窗口中,使其对整个应用程序生效。
但是我在我的-DDLIB_JPEG_SUPPORT文件中设置了.pro,链接到jpeg和png,甚至下载到工作文件夹共享库jpeg.dll中。如何解决这个问题,或者如何在Windows上使用Qt中的dlib?
UPD:E:\CMake\bin\cmake.exe --build . --config Release后的错误
"C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\3d_point_cloud_ex.vcxproj" (default target)
(3) ->
"C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj" (default target) (4
) ->
(target ClCompile) ->
f:\gstreamer\1.0\x86\include\jmorecfg.h(211): error C2371: 'boolean': redefinition; different basic types [C:\Users\user
\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj]
C:\Program Files (x86)\Windows Kits\8.1\Include\shared\basetsd.h(72): error C2371: 'INT32': redefinition; different b
asic types [C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj]
c:\program files (x86)\windows kits\8.1\include\shared\rpcndr.h(178): error C2371: 'boolean': redefinition; different
basic types [C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj]
c:\program files (x86)\windows kits\8.1\include\shared\wtypesbase.h(493): error C2371: 'BOOLEAN': redefinition; diffe
rent basic types [C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj]UPD2:
"C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\3d_point_cloud_ex.vcxproj" (default target) (3) ->
"C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj" (default target) (4) ->
(target ClCompile) ->
C:\Users\user\Downloads\dlib-19.0\dlib-19.0\dlib\image_loader\jpeg_loader.cpp(17): fatal error C1083: Cannot open include file: 'jpeglib.h': No such file or directory [C:\U
sers\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj]
C:\Users\user\Downloads\dlib-19.0\dlib-19.0\dlib\image_saver\save_jpeg.cpp(16): fatal error C1083: Cannot open include file: 'jpeglib.h': No such file or directory [C:\User
s\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj]UPD3:
.pro文件:
INCLUDEPATH += "E:\dlib_build\include"
LIBS += -L"E:\dlib_build"
LIBS += -ldlib
QMAKE_CXXFLAGS_RELEASE += /arch:AVX
QMAKE_CXXFLAGS += -std=c++11 -DDLIB_PNG_SUPPORT -DDLIB_JPEG_SUPPORTMSVC 2015 64位发布输出:
mainwindow.obj : error LNK2019: unresolved external symbol "public: __cdecl dlib::entropy_decoder_kernel_2::entropy_decoder_kernel_2(void)" (??0entrop...
mainwindow.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2(void)" (...
mainwindow.obj : error LNK2019: unresolved external symbol "public: void __cdecl dlib::entropy_decoder_kernel_2::set_stream(class std::basic_istream<c...
mainwindow.obj : error LNK2019: unresolved external symbol "public: void __cdecl dlib::entropy_decoder_kernel_2::decode(unsigned int,unsigned int)" (?...
mainwindow.obj : error LNK2019: unresolved external symbol "public: unsigned int __cdecl dlib::entropy_decoder_kernel_2::get_target(unsigned int)" (?g...
mainwindow.obj : error LNK2019: unresolved external symbol "public: __cdecl dlib::png_loader::png_loader(class std::basic_string<char,struct std::char...
mainwindow.obj : error LNK2019: unresolved external symbol "public: __cdecl dlib::png_loader::~png_loader(void)" (??1png_loader@dlib@@QEAA@XZ) referen...
mainwindow.obj : error LNK2019: unresolved external symbol "public: bool __cdecl dlib::png_loader::is_gray(void)const " (?is_gray@png_loader@dlib@@QEB...
mainwindow.obj : error LNK2019: unresolved external symbol "public: bool __cdecl dlib::png_loader::is_graya(void)const " (?is_graya@png_loader@dlib@@Q...
mainwindow.obj : error LNK2019: unresolved external symbol "public: bool __cdecl dlib::png_loader::is_rgb(void)const " (?is_rgb@png_loader@dlib@@QEBA_...
mainwindow.obj : error LNK2019: unresolved external symbol "public: bool __cdecl dlib::png_loader::is_rgba(void)const " (?is_rgba@png_loader@dlib@@QEB...
mainwindow.obj : error LNK2019: unresolved external symbol "private: unsigned char const * __cdecl dlib::png_loader::get_row(unsigned int)const " (?ge...
mainwindow.obj : error LNK2019: unresolved external symbol "public: __cdecl dlib::jpeg_loader::jpeg_loader(class std::basic_string<char,struct std::ch...
mainwindow.obj : error LNK2019: unresolved external symbol "public: bool __cdecl dlib::jpeg_loader::is_gray(void)const " (?is_gray@jpeg_loader@dlib@@Q...
mainwindow.obj : error LNK2019: unresolved external symbol USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSER...
E:\dlib_build\lib\dlib.lib : warning LNK4272: library machine type 'X86' conflicts with target machine type 'x64'
release\dlibWindows.exe : fatal error LNK1120: 15 unresolved externals
jom: F:\Projects\QtProjects\build-dlibWindows-Desktop_Qt_5_6_0_MSVC2015_64bit-Release\Makefile.Release [release\dlibWindows.exe] Error 1120UPD4:
.pro文件:
INCLUDEPATH += "E:\dlib_build\include"
LIBS += -L"E:\dlib_build"
LIBS += -ldlib
QMAKE_CXXFLAGS_RELEASE += /arch:AVX代码:
try
{
//or even just one line "frontal_face_detector detector = get_frontal_face_detector();"
array2d<rgb_pixel> img;
load_image(img, "C:/Users/user/Downloads/test.jpg");
}
catch (exception& e)
{
cout << "\nexception thrown!" << endl;
cout << e.what() << endl;
}释放产出:
与代码255一起退出
发布于 2016-07-01 06:52:00
通过将all/source.cpp包含到项目中,您已经选择了编译方式。这是可能的,但我认为这不是如何使用dlib的最佳方式。因此,如果您想在您的项目中使用all/source.cpp -请按照这里的说明:http://dlib.net/compile.html
使用Visual在Windows上编译 您所需要做的就是创建一个空控制台项目。然后将dlib /all/ search e.cpp添加到其中,并将包含dlib文件夹的文件夹添加到#include搜索路径。然后,您可以通过将它添加到项目中来编译任何示例程序。 同样,请注意,只有在libjpeg和libpng中链接时,dlib才能处理jpeg和png文件。在Visual中,最简单的方法是将dlib/外部文件夹中的所有源文件添加到项目中,并定义DLIB_PNG_SUPPORT和DLIB_JPEG_SUPPORT预处理器指令。如果您不知道如何配置Visual,那么您应该使用上面所示的CMake,因为它将自动处理所有事情。
通过添加dlib/外部文件夹,您可以从项目中删除libjpeg和libpng。
但正如我所说--这不是编译dlib的最佳方法。Dlib被设计用于CMAKE,最好的方法是使用CMAKE构建它。为什么这样做更好:
在这里,第一步(安装CMAKE之后)应该检查Dlib是否有效。根据dlib的说明,最好的方法是构建示例并运行它们(从dlib的文件夹):
cd examples
mkdir build
cd build
cmake ..
cmake --build . --config Release在运行cmake.时,可以指定编译器版本,例如:
cmake .. -G"Visual Studio 14 2015 Win64" 使用Visual 2015 x64构建示例
在测试示例之后,现在是构建Dlib并开始在实际项目中使用它的好时机。是的,同样由CMAKE (来自dlib文件夹)完成构建:
mkdir build
cd build
cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=C:\Users\user\dlib
cmake --build . --config Release --target install构建过程与构建示例没有什么不同:
在构建过程完成之后-您可以使用C:\user\user\dlib\lib中的dlib.lib (静态版本的Dlib)。如果您将使用CMAKE与您的项目-您将需要添加-DCMAKE_PREFIX_PATH=c:\Users\user\dlib。但是现在您正在尝试使用(QMake)进行编译。下面是您的.pro文件的外观(可能的最小示例):
SOURCES += face_detection_ex.cpp
INCLUDEPATH += "C:\Users\user\dlib\include"
LIBS += -L"C:\Users\user\dlib"
LIBS += -ldlib
QMAKE_CXXFLAGS_RELEASE += /arch:AVX这个项目不会在Debug模式下编译和运行,因为我们在构建过程中使用了--config版本。但是发布模式将运行得非常快。
请注意
https://stackoverflow.com/questions/38136699
复制相似问题