Reputation: 3108
I want to edit some jpeg files with c++. I linked to libjpg and compiled my code. Compiler complained about typedefs FILE and size_t. I googled the problem and found out that this library is designed to compile under C not C++ so we have to manually add include stdio.h to "jpeglib.h". I did that but this time compiler gave me the folloeing errors:
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
It can't find the library functions. If I delete the stdio.h line and compile again I get this:
‘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-
What am I supposed to do?
Upvotes: 1
Views: 1969
Reputation: 9446
Put the #include back. But it looks awfully like you are not adding a -ljpeg or something similar when you are linking. Also you need to make sure that if you are including this in C++ code you may need to do:
extern "C" {
#include <jpeglib.h>
}
Upvotes: 6