c++ - 不能在 dlib cpp 文件中包含 JPEG_SUPPORT header

标签 c++ c++11 jpeg header-files dlib

我正在尝试编译一个 cpp 文件:dlib 中的面部查找器:http://dlib.net/face_detection_ex.cpp.html .但是当我运行它时,它说我必须包含 jpg 和 png 文件的库:

processing image /home/james/Work/Coding/Sources/Image/950.jpg

exception thrown!
Unable to load image in file /home/dave/Code/Resources/Images/500.jpg.
You must #define DLIB_JPEG_SUPPORT and link to libjpeg to read JPEG files.
Do this by following the instructions at http://dlib.net/compile.html.

Note that you must cause DLIB_JPEG_SUPPORT to be defined for your entire project.
So don't #define it in one file. Instead, use a compiler switch like -DDLIB_JPEG_SUPPORT
so it takes effect for your entire application.

我尝试使用 -DDLIB_JPEG_SUPPORT 标志,但失败了,所以我试图在文件中定义它们:

*/

#define DLIB_JPEG_SUPPORT
#define DLIB_PNG_SUPPORT

#include </home/james/dlib/image_io.h>
#include </home/james/dlib/image_processing/frontal_face_detector.h>
#include </home/james/dlib/gui_widgets.h>
#include </home/james/dlib/image_io.h>
#include <iostream>

using namespace dlib;
using namespace std;

// ----------------------------------------------------------------------------------------

int main(int argc, char** argv)

但是编译失败:

james@james-Toshiba-Satellite-8505:~/Work/Coding/Cpp/Dlib/Examples$ g++ -std=c++11 -O3 -I.. ~/dlib/all/source.cpp -lpthread -lX11 face_detection_ex.cpp -o face_detection_ex_2/tmp/ccVHitZj.o: In function `main':
face_detection_ex.cpp:(.text.startup+0x1c0d): undefined reference to `dlib::jpeg_loader::jpeg_loader(std::string const&)'
face_detection_ex.cpp:(.text.startup+0x1d0a): undefined reference to `dlib::jpeg_loader::is_gray() const'
face_detection_ex.cpp:(.text.startup+0x1e3b): undefined reference to `dlib::png_loader::png_loader(std::string const&)'
face_detection_ex.cpp:(.text.startup+0x1f04): undefined reference to `dlib::png_loader::is_gray() const'
face_detection_ex.cpp:(.text.startup+0x1f23): undefined reference to `dlib::png_loader::is_gray() const'
face_detection_ex.cpp:(.text.startup+0x1f38): undefined reference to `dlib::png_loader::is_graya() const'
face_detection_ex.cpp:(.text.startup+0x1f59): undefined reference to `dlib::png_loader::is_graya() const'
face_detection_ex.cpp:(.text.startup+0x1f6e): undefined reference to `dlib::png_loader::is_rgb() const'
face_detection_ex.cpp:(.text.startup+0x1f83): undefined reference to `dlib::png_loader::is_rgb() const'
face_detection_ex.cpp:(.text.startup+0x1f98): undefined reference to `dlib::png_loader::is_rgba() const'
face_detection_ex.cpp:(.text.startup+0x1fad): undefined reference to `dlib::png_loader::is_rgba() const'
face_detection_ex.cpp:(.text.startup+0x2009): undefined reference to `dlib::png_loader::get_row(unsigned int) const'
face_detection_ex.cpp:(.text.startup+0x20b6): undefined reference to `dlib::png_loader::get_row(unsigned int) const'
face_detection_ex.cpp:(.text.startup+0x211c): undefined reference to `dlib::png_loader::~png_loader()'
face_detection_ex.cpp:(.text.startup+0x229a): undefined reference to `dlib::png_loader::get_row(unsigned int) const'
face_detection_ex.cpp:(.text.startup+0x2587): undefined reference to `dlib::png_loader::get_row(unsigned int) const'
face_detection_ex.cpp:(.text.startup+0x2ea7): undefined reference to `dlib::png_loader::~png_loader()'
face_detection_ex.cpp:(.text.startup+0x2fe9): undefined reference to `dlib::png_loader::get_row(unsigned int) const'
face_detection_ex.cpp:(.text.startup+0x30ac): undefined reference to `dlib::png_loader::get_row(unsigned int) const'
face_detection_ex.cpp:(.text.startup+0x313c): undefined reference to `dlib::png_loader::get_row(unsigned int) const'
face_detection_ex.cpp:(.text.startup+0x31c4): undefined reference to `dlib::png_loader::get_row(unsigned int) const'
collect2: error: ld returned 1 exit status

最佳答案

请在提问之前阅读编译器和工具向您显示的错误和建议消息。

About:
exception thrown! Unable to load image in file /home/dave/Code/Resources/Images/500.jpg. You must #define DLIB_JPEG_SUPPORT and link to libjpeg to read JPEG files. Do this by following the instructions at http://dlib.net/compile.html.

安装libjpeg、libpng等库,并在编译时使用它们来链接程序。请阅读建议页面 http://dlib.net/compile.html .

如果您有多个源代码文件,则在编译之前从您的代码中删除预处理器指令。

#define DLIB_JPEG_SUPPORT
#define DLIB_PNG_SUPPORT

并使用建议的开关编译器:-DDLIB_JPEG_SUPPORT。

Note that you must cause DLIB_JPEG_SUPPORT to be defined for your entire project. So don't #define it in one file. Instead, use a compiler switch like -DDLIB_JPEG_SUPPORT so it takes effect for your entire application.

所以,使用这样的命令来编译:

g++ face_detection_ex.cpp -o face_detection_ex_2 -std=c++11 -O3 -I.. ~/dlib/all/source.cpp -lpthread -lX11 -ljpeg -lpng -DDLIB_JPEG_SUPPORT -DDLIB_PNG_SUPPORT

假设库(libjpeg 和 libpng)已经安装。

关于c++ - 不能在 dlib cpp 文件中包含 JPEG_SUPPORT header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43017973/

相关文章:

C++/Boost:将成员函数作为参数传递给 boost::bind

c++ - 有可能有一个动画 QSystemTrayIcon 吗?

c++ - pragma omp for inside pragma omp master or single

c++ - 在 C++ 中弹出任何元素后自动调整数组大小

windows - 使用鼠标光标捕获屏幕截图

android - Canvas 上的图像到 JPEG 文件

C++ 字符串 - 使用初始化列表构造函数时的奇怪行为

c++ - 使 C++14 constexpr 函数与 C++11 兼容

C++ 错误 : braces around scalar initializer for type 'bool'

php - 使用 PHP 将 JPG 合并为一个 PDF