Thread: How compile IJP (jpeg library) on Windows in CodeBlocks IDE

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    235

    How compile IJP (jpeg library) on Windows in CodeBlocks IDE

    Note, I am runnin x86 machine and Win XP.

    Finally I have found library to work with jpeg images
    Independent JPEG Group

    In the install.txt I have read I need to create makefile but don't know how. There are already dome makefiles, eg. makefile.vc but I think I need file for codeblocks.

  2. #2
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    This belongs in the Windows board, not the C board.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    I think you'll probably need to build it from the command line. Most library distributions like that aren't available with project files for a particular IDE. You may be able to import the makefile with code::blocks. I'm not really sure what capabilities it has in that respect, but it's possible that it has an option to create a project by importing a makefile.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Elkvis View Post
    I think you'll probably need to build it from the command line. Most library distributions like that aren't available with project files for a particular IDE. You may be able to import the makefile with code::blocks. I'm not really sure what capabilities it has in that respect, but it's possible that it has an option to create a project by importing a makefile.
    Code::Blocks (CB) does NOT have the ability to convert an makefile to a normal CB Project.
    But, it does have a option to use a custom makefile CB project instead of doing a normal CB Project.

    But, it is much easier and faster to compile the makefile on the command line.
    And, then if you need to do it again to create a CB custom makefile project.

    Newbies tend to fail on creating CB custom makefile projects.
    But, the people who know both normal CB Projects and GNU makefiles have only slight problem doing it.


    NOTE: I think CB only support GNU makefiles; but, it might support others. I have only tried GNU makefiles, myself.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Sep 2014
    Posts
    235
    I am completely lost and don't know what to do. What option in CB? Where is it? I don't see any custom makefile project in New project. But CB does not have any command line as far as I know so how can I compile it on command line? There are some programs in MinGW\bin but I don't know if I can use them to compile project. I know only Visual Studio C++ which has command line (I don't have it installed].

    Also I don't know which files I need for the project. There are also some testing files with examples.
    Last edited by barracuda; 01-26-2015 at 04:46 PM.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Ignore that CB exists!

    Open an command line normally cmd.exe

    Type the make command needed to make the library build.
    NOTE: This requires you to read the library documentation and likely to know information about the compiler you plan to use.
    NOTE: Code::Blocks is NOT a Compiler.

    Edit: I am lazy, so, I would try GnuWin32 build and see if it works for me before trying to build the library myself.
    http://gnuwin32.sourceforge.net/packages/jpeg.htm

    Tim S.
    Last edited by stahta01; 01-26-2015 at 04:52 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    Registered User
    Join Date
    Sep 2014
    Posts
    235
    But I want the library from Independent jpeg Group:
    Independent JPEG Group
    Not sure if that is the library you linked. You linked 10 years old library, the library from IJG is updated 2014.

    I have downloaded the make.exe and dependencies. What to do then? I would use gcc. Oops, now I have found:mingw32-make.exe file located in MinGW\bin
    Last edited by barracuda; 01-26-2015 at 05:19 PM.

  8. #8
    Registered User
    Join Date
    Sep 2014
    Posts
    235
    I searched for binaries for newest version (9a) and found this page:
    JPEGclub.org
    but I did not find the *.dll or *.lib. The binaries contain only *.exe

    Do you know some modern library, different from libjpeg which is not old like hell? Because libjpeg's latest release is version 6b of 27-Mar-1998 ...

    Same author IJG realeses version 9a but I cannot find the libraries.

  9. #9
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    On x86, x86-64, and ARM architectures the libjpeg-turbo, a vectorized derivative of the IJG JPEG library, is usually more efficient, and that's what is installed in my Linux machine. It seems to be well maintained.

    The latest version (January 2015) is 1.4.0, and the official downloads include sources, Linux packages, Mac OS X disk image for installation, as well as self-extracting archives for different compilers for Windows.

    The library supports the same API as IJG JPEG library, but also supports a "turbo" API of it's own. Both are portable, since both these libraries are quite portable, so use the one you're more comfortable with.

    In particular, the libjpeg-turbo-1.4.0-gcc.exe is a self-extracting archive for 32-bit GCC in Windows. If you do not want to execute it, you can also use 7zip to open it as an archive. (I checked on my Linux machine.) If you only want the static libraries (assuming you want to compile a static binary for ease of use), just grab the libjpeg.a and libturbojpeg.a files from the lib directory in the archive, and the header files from the include directory, and you're ready to go. Otherwise, check the documentation; I don't know the details on how to set up the dynamic libraries in Windows.

    GCC needs -Iinclude compiler flag to point to the include files, and -Llib to point to the library files, and -static flag to compile a static binary. I don't know how you set those in Code::Blocks. However, if you create an empty project and it creates a Makefile, then check if you have a CFLAGS and LDFLAGS assignments near the beginning. Typically, you'll want something like
    Code:
    CFLAGS := -Wall -std=c99 -Ipathtoincludedirectory
    LDFLAGS := -Lpathtolibrarydirectory -ljpeg -lturbojpeg
    Hopefully a Windows user with Code::Blocks will help you setting up your project.

  10. #10
    Registered User
    Join Date
    Sep 2014
    Posts
    235
    Thanks, I will try it.

    In the meanwhile I have successfully installed MingGW and MingGW shell and I have tried to compile the libjpeg 9a - seemed all works fine except that on the end of messaging after I used the command make I got few errors. I don't know how to import specific makefile, but it seems it auto-choosed some make file.

  11. #11
    Registered User
    Join Date
    Sep 2014
    Posts
    235
    I am trying to compile the jpeg-turbo library.

    Which file do I need to add to linker?
    \bin\libturbojpeg.dll
    and
    \lib\libturbojpeg.dll.a
    to linker.
    or the libjpeg?

    When I use the libjpeg.dll and libjpeg.a with the example code I got error:
    main.c|127|undefined reference to `put_scanline_someplace'|

    Is this line:
    Code:
    put_scanline_someplace(buffer[0], row_stride); // args: pointer & sample count.
    what I should change? And if yes, should not be there something like:
    buffer[i]?

    I am not sure how to solve this.

  12. #12
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    Quote Originally Posted by Nominal Animal View Post
    If you only want the static libraries (assuming you want to compile a static binary for ease of use), just grab the libjpeg.a and libturbojpeg.a files from the lib directory in the archive, and the header files from the include directory, and you're ready to go. Otherwise, check the documentation; I don't know the details on how to set up the dynamic libraries in Windows.
    Let me put it in another words:

    If you were compiling your own program, say myprog.c to a static binary, myprog.exe, and you had lib\libjpeg.a and lib\libturbojpeg.a and the library headers in include\,
    Code:
    gcc -Wall -O2 -static -Iinclude -Llib myprog.c -ljpeg -lturbojpeg -o myprog.exe
    should do the trick.

    I suspect, but don't know and don't even really want to know as I don't really care one way or another, but for a dynamic build in Windows you probably need bin\libjpeg.dll and bin\libturbojpeg.dll and the library headers in include\,
    Code:
    gcc -Wall -O2 -Iinclude -Lbin myprog.c -ljpeg -lturbojpeg -o myprog.exe
    should work. I guess.

    Again, that's just a straightforward guess. I only use Linux. Like I posted earlier, this is Windows stuff, and has nothing, really, to do with C.

  13. #13
    Registered User
    Join Date
    Sep 2014
    Posts
    235
    I successfully compiled the project. Thanks. Can I ask something about the library or is it prohibited?

  14. #14
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    Quote Originally Posted by barracuda View Post
    Can I ask something about the library
    Sure, go ahead.
    Quote Originally Posted by barracuda View Post
    or is it prohibited?
    I only said that this thread belongs in the Windows board. Apparently the admins disagree, or they would have moved the thread.

  15. #15
    Registered User
    Join Date
    Sep 2014
    Posts
    235
    Nice. So my problem is that I don't know how to copy data to the buffer of the raster image.

    Code:
    // shorten a bit
    int read_JPEG_file (char * filename, char * RGB_buffer); // declaration of reading
    int main()
    {
    char * filename = "sourcefile.jpg";
    char * RGB_buffer; // Final image
    read_JPEG_file(filename, RGB_buffer); // read the image
        return 0;
    }
    
    // implementation here - shorten
    ...
      while (cinfo.output_scanline < cinfo.output_height) {
        // strcpy(RGB_buffer, const char *src ---> buffer); // cannot use buffer, it is not const
        // (void) jpeg_read_scanlines(&cinfo, buffer, 1);
    ...
    So how copy the buffer, obviously I cannot use strcpy.

    Subquestion: Is it possible to add or use HSV colorspace? Reading the image directly into HSV could save me a lot of memory resources later. Otherwise I would need to do the RGB-->HSV conversion later.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Installing c library in codeblocks
    By kostaras14 in forum C Programming
    Replies: 20
    Last Post: 01-30-2014, 03:39 AM
  2. Windows 7 64b & CodeBlocks
    By Gingitzu in forum Windows Programming
    Replies: 3
    Last Post: 08-20-2011, 10:25 PM
  3. How to use loadJPG function from library jpeg?
    By CNoobgrammer in forum C Programming
    Replies: 77
    Last Post: 07-31-2011, 01:56 AM
  4. Cant compile using Codeblocks 10.05
    By laimaretto in forum Windows Programming
    Replies: 2
    Last Post: 12-15-2010, 12:24 PM
  5. library issues in CodeBlocks
    By everlearnin in forum C++ Programming
    Replies: 0
    Last Post: 06-02-2009, 08:44 PM