我想用c ++编辑一些jpeg文件。我链接到libjpg并编译了我的代码。编译器抱怨typedef FILE和size_t。我搜索了这个问题,发现这个库是为了在C而不是C ++下编译的,所以我们必须手动将include stdio.h添加到“jpeglib.h”。我做到了,但这次编译器给了我以下错误:
undefined reference to `jpeg_CreateCompress' JPGImage.cpp /KFCK/src line 47 C/C++ Problem
undefined reference to `jpeg_CreateDecompress' JPGImage.cpp /KFCK/src line 92 C/C++ Problem
undefined reference to `jpeg_destroy_compress' JPGImage.cpp /KFCK/src line 77 C/C++ Problem
undefined reference to `jpeg_destroy_decompress' JPGImage.cpp /KFCK/src line 123 C/C++ Problem
undefined reference to `jpeg_finish_compress' JPGImage.cpp /KFCK/src line 74 C/C++ Problem
undefined reference to `jpeg_finish_decompress' JPGImage.cpp /KFCK/src line 120 C/C++ Problem
undefined reference to `jpeg_read_header' JPGImage.cpp /KFCK/src line 102 C/C++ Problem
undefined reference to `jpeg_read_scanlines' JPGImage.cpp /KFCK/src line 115 C/C++ Problem
undefined reference to `jpeg_set_defaults' JPGImage.cpp /KFCK/src line 61 C/C++ Problem
undefined reference to `jpeg_set_quality' JPGImage.cpp /KFCK/src line 62 C/C++ Problem
undefined reference to `jpeg_start_compress' JPGImage.cpp /KFCK/src line 65 C/C++ Problem
undefined reference to `jpeg_start_decompress' JPGImage.cpp /KFCK/src line 104 C/C++ Problem
找不到库函数。如果我删除stdio.h行并再次编译,我得到这个:
‘FILE’ has not been declared KFCK line 956, external location: /home/../jpeg-8c/jpeglib.h C/C++ Problem
‘FILE’ has not been declared KFCK line 957, external location: /home/../jpeg-8c/jpeglib.h C/C++ Problem
‘size_t’ does not name a type KFCK line 756, external location: /home/../jpeg-8c/jpeglib.h C/C++ Problem
‘size_t’ does not name a type KFCK line 768, external location: /home/../jpeg-8c/jpeglib.h C/C++ Problem
‘size_t’ has not been declared KFCK line 799, external location: /home/../jpeg-
我应该做什么?
答案 0 :(得分:4)
把#include放回去。但它看起来非常像你在链接时没有添加-ljpeg或类似的东西。此外,您需要确保如果您在C ++代码中包含此内容,则可能需要执行以下操作:
extern "C" {
#include <jpeglib.h>
}