Thread: trouble using libjpeg

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    5

    trouble using libjpeg

    I am trying to get the sample code provided in libjpeg. i am getting some linker errors.
    I followed the instructions provided in the following site
    Compile LibJPEG

    But i keep getting this linker error. The followin is my code
    Code:
    #include <stdio.h>
    extern "C"
    {
    #include "jpeglib.h"
    }
    #include <setjmp.h>
    #include <stdlib.h>
    extern JSAMPLE *image_buffer;	/* Points to large array of R,G,B-order data */
    int image_height = 576;	/* Number of rows in image */
    int image_width = 768;		/* Number of columns in image */
    GLOBAL(void) write_JPEG_file (char * filename, int quality)
    {
    	struct jpeg_compress_struct cinfo;
    	struct jpeg_error_mgr jerr;
    	FILE * outfile;
    	JSAMPROW row_pointer[1];
    	int row_stride;
    	cinfo.err = jpeg_std_error(&jerr);
    	jpeg_create_compress(&cinfo);
    	if ((outfile = fopen(filename, "wb")) == NULL) {
        fprintf(stderr, "can't open %s\n", filename);
        exit(1);
      }
      jpeg_stdio_dest(&cinfo, outfile);
       cinfo.image_width = image_width; 	/* image width and height, in pixels */
      cinfo.image_height = image_height;
      cinfo.input_components = 3;		/* # of color components per pixel */
      cinfo.in_color_space = JCS_RGB; 
    
    
       jpeg_set_defaults(&cinfo);
       jpeg_set_quality(&cinfo, quality, TRUE);
    
       jpeg_start_compress(&cinfo, TRUE);
       row_stride = image_width * 3;
    
    
    
       while (cinfo.next_scanline < cinfo.image_height) {
    	   row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
        (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
      }
    
       jpeg_finish_compress(&cinfo);
       fclose(outfile);
       jpeg_destroy_compress(&cinfo);
    
    }
    int main()
    {
    	write_JPEG_file("my_bitmap.bmp",3);
    	return 0;
    
    }
    Can anyone tell me where i have gone wrong?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Without you telling us the errors you actually get, we can just guess based on historical trends. The historical trends say that you don't know how to work your compiler, and that you need to properly set up the project options/linker options to actually use the library (NOTE CAREFULLY: typing a #include line in your code does not do anything at all when it comes to actually bringing the library into a project).

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    5
    Error 2 error LNK2019: unresolved external symbol _jpeg_destroy_compress referenced in function "void __cdecl write_JPEG_file(char *,int)" (?write_JPEG_file@@YAXPADH@Z) c:\Users\t_DivyaR\documents\visual studio 2010\Projects\jpeg-comp1\jpeg-comp1\t1.obj jpeg-comp1

    Error 3 error LNK2019: unresolved external symbol _jpeg_finish_compress referenced in function "void __cdecl write_JPEG_file(char *,int)" (?write_JPEG_file@@YAXPADH@Z) c:\Users\t_DivyaR\documents\visual studio 2010\Projects\jpeg-comp1\jpeg-comp1\t1.obj jpeg-comp1

    These are the type of errors i am getting. I followed all the instructions given in the link. Could you highlight on what needs to be done to set up the project in Visual Studio for working with libjpeg

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You need to do what it says you should do:
    Quote Originally Posted by link above
    For your Visual Studio Projects, select the project > open context menu > properties > configuration properties > linker > input > additional dependencies and add libjpeg.lib if you are building an executable or add libjpeg.lib to project > open context menu > properties > Configuration Properties > Librarian > Additional Dependencies if you are building a library.
    Make sure you have put the .lib file where it belongs already.

  5. #5
    Registered User
    Join Date
    Jul 2011
    Posts
    5
    But in there is no librarian in the context-menu->configuration. Also where can i find resources to work on libjpeg??

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Are you trying to build a library? If not, then don't try to find that, because it isn't there. If so, make sure you set up your project as a library, and not a windows project or whatever.

  7. #7
    Registered User
    Join Date
    Jul 2011
    Posts
    5

    Still unable to fix the problem

    I am encountering this error while linkin

    Error 4 error LNK2019: unresolved external symbol "void __cdecl jpeg_start_compress(struct jpeg_compress_struct *,unsigned char)" (?jpeg_start_compress@@YAXPAUjpeg_compress_struct@ @E@Z) referenced in function _main

    Any idea how to link my program to reference the libjpeg libraries?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    What about project->settings ?
    Somewhere there will be a dialog allowing you to set up additional linker search paths and additional linker libraries.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linker error when using libjpeg
    By s-men in forum C++ Programming
    Replies: 2
    Last Post: 08-21-2008, 10:02 AM
  2. libjpeg problems linking in cpp
    By parad0x13 in forum C++ Programming
    Replies: 4
    Last Post: 07-19-2008, 04:29 PM
  3. Lib issues: undefined references (libjpeg)
    By psychopath in forum Linux Programming
    Replies: 3
    Last Post: 04-17-2006, 01:28 PM
  4. libjpeg sgefault on jpeg_read_scanlines()
    By Syko in forum C Programming
    Replies: 6
    Last Post: 11-27-2005, 02:14 AM
  5. Compiler errors when using libjpeg.
    By Nikanoru in forum C++ Programming
    Replies: 11
    Last Post: 08-07-2003, 06:46 AM

Tags for this Thread