LNK2019 Error with jpeg.lib

This is a discussion on LNK2019 Error with jpeg.lib within the C++ Programming forums, part of the General Programming Boards category; I have been trying to add jpeg loading code to an MFC application in Visual Studio 2005. I'm not sure ...

  1. #1

    Join Date
    May 2005
    Posts
    1,041

    LNK2019 Error with jpeg.lib

    I have been trying to add jpeg loading code to an MFC application in Visual Studio 2005. I'm not sure if I'm linking in a bad order or using improper compiler options, etc. I've been poking around for well over an hour, I'm sure this is something minor, but when I add my texture loading code, which uses jpeg.lib, I get the following error:

    1>jpeg.lib(jerror.obj) : error LNK2019: unresolved external symbol __iob referenced in function _output_message
    1>.\Debug/Viewer.exe : fatal error LNK1120: 1 unresolved externals
    Any ideas?
    I'm not immature, I'm refined in the opposite direction.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Hmm ... sounds like the library was compiled with an older version of VC++. Did you compile the jpeglib project yourself, or use a precompiled version?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3

    Join Date
    May 2005
    Posts
    1,041
    jpeg is precompiled. I've got another project, which was converted from VS2003 to VS 2005, working with the jpeg library, but this MFC project, which I believe was written from scratch in VS 2005, can't take the jpeg code without the linker error, and I'm really not sure which compiler options might have screwed this up.
    I'm not immature, I'm refined in the opposite direction.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Try the various options for the C runtime library (static, dynamic, ...). The symbol it complains about comes from there.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5

    Join Date
    May 2005
    Posts
    1,041
    I think that with your suggestion I may be on the right track, but I'm not *quite* there yet. I've tried the following suggestions from the following site (with your input as a guide):

    http://www.tc.cornell.edu/SoftwarePages/Migrating+to+Visual+Studio+2005+from+Visual+Studio +.NET+2003.htm

    If you prefer static linking (the VS2003 default), do the following for each project in your solution: Go to Properties | Configuration | C/C++ | Code Generation | Runtime Library.

    Release: Change /MD to /MT, Multithreaded.
    Debug: Change /MDd to /MTd, Debug Multithreaded.
    These changes belch out errors from afxwin.h:

    afxver_.h(77) : fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds
    I'm not immature, I'm refined in the opposite direction.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Yes, dynamic MFC linking is incompatible with static CRT linking.

    You can try static MFC linking to see if using the static CRT solves your linking problem. However, be aware that static MFC linking makes your application a *lot* bigger. If you have several components that use the MFC, this is not advisable.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7

    Join Date
    May 2005
    Posts
    1,041
    Other than the switches mentioned above, what other options might I try changing?

    As I see it, I really just ought to find a more recent build of the jpeg.lib, which is what I'm trying to do (I re-downloaded a jpeg.lib but got the same results).

    So the reason the other static .lib files linked to this project don't fail is that they weren't compiled with the same C-runtime dependencies as the jpeg.lib? I'm having a hard time actually appreciating what these problems mean (right now they still just seem a bit absurd, and very frustrating).

    EDIT:

    I went back and re-created the project, instead opting for linking with MFC in a static library, re-compiled, and the JPEG funcitonality is working. But the same code with static creates a 3.17MB executable, and the original project (same exact source, minus the jpeg part) builds an executable of 280KB. That's a pretty significant size difference.

    So, do you think I ought to try rebuilding the actual JPEG .lib in VS2005? It'd be pretty nice to not have to needlessly inflate the final binary.
    Last edited by BobMcGee123; 11-23-2008 at 02:40 AM.
    I'm not immature, I'm refined in the opposite direction.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It's certainly an option. Probably the best one. You should be able to get the source of jpeglib pretty easily.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9

    Join Date
    May 2005
    Posts
    1,041
    Hey there I just wanted to upload the jpeg.lib static library that works with visual studio 2005, linking to MFC dynamically. When I searched the net I found a lot of people were having something of a similar problem. Just to recap, I could use the 'old' jpeg.lib (presumably built with an older version of visual studio, e.g. 2003 or earlier) only if I linked to MFC statically. This unnecessarily inflated the final binary to about 3 MB, up from only about 200KB.

    Also, here are two sites that helped me with the details. I used the first site to get the source (see section 3.3), as well as premade sln. and vcproj files as well as the proper jconfig.h for VS2005.

    The second link simply talks about some of the compiler switches that had been changed between when vs 2005 was made (explaining what CornedBeef had talked about earlier).

    http://www.spy-hill.net/~myers/help/...n-windows.html

    http://blogs.msdn.com/branbray/archi...08/437078.aspx

    Links for the files:
    http://www.yourfilehost.com/media.ph...eglib_VS2005.h
    http://www.yourfilehost.com/media.ph...peg_VS2005.lib
    I'm not immature, I'm refined in the opposite direction.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. VC++ a POS
    By Welder in forum Windows Programming
    Replies: 40
    Last Post: 11-07-2007, 03:07 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  4. wxWidgets link problem
    By cboard_member in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2006, 02:36 PM
  5. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21