Question

I need JPEG handling capabilities in my project so I decided to use jpeg-8d library, after downloading packages I've made usual ./configure; make and make install. make test returns no errors and no problems was reported during the whole process but when I opened example.c in Code Blocks 10.05 compilation failed. I've "googled" some solutions and added

#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}
#endif

In jpeglib.h file, recompiled, then added these lines to linker section of code blocks: /usr/local/lib/libjpeg.a /usr/local/lib/libjpeg.so also added according directories into directories section. but compiler still fails to compile example.c, here are some of the errors:

> /home/raff/CodeBlocks/jpeg-8d/example.c|116|warning: incompatible implicit declaration of built-in function ‘exit’|
> example.c|| undefined reference to 'image_width'
> example.c|| undefined reference to 'image_height'

If anyone successfully installed and used jpeg library please help, I have no problem in switching IDE and/or linux distribution.

Was it helpful?

Solution

Your instalation of the library seems to be fine (otherwise it would complain about missing jpeglib.h during compilation)

The file example.c is supposed to be part of documentation, not a code you can compile and use. Note that there's no main(), for example. You should use it as a reference on how to code methods for compressing and decompressing jpeg files.

The variables image_width and image_height (and image_buffer) are declared as extern, so they are assumed to be defined in some other file. You can write your program defining those variables and filling up the buffer and only after that you can use the provided methods (write_JPEG_file and read_JPEG_file).

OTHER TIPS

  1. Are you linking with static or shared library?
  2. If it's static, do you place it after the object files in linker's command line?
  3. If it's shared, and you're using newer toolchain, this may also be the issue.
  4. If you're linking correctly, what does readelf -s show on the shared library? What does nm show on static library?

I was so sure that example.c was in fact an example of using this library that I did not check for its content. Moreover there was some more problems. After writing proper program I`ve encountered an error:

error while loading shared libraries libjpeg.so.8: cannot open shared object file: No such file or directory

But this was fixed by this pair of shell commands:

ranlib /usr/local/lib/libjpeg.a
ldconfig /usr/local/lib

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top