Click here to Skip to main content
15,944,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone,

My compiler keeps telling me I have a linker error:

libpng.lib(pngerror.obj) : error LNK2019: unresolved external symbol __iob referenced in function _png_default_error


I think this is referring to libpng library, but I am unsure what it is telling me to do to fix it? Is this a standard library that I should include under additional dependencies or something I need to physically add?

I have tried: Adding libc.lib and msvcrt.lib to 'ignore default libraries' and added libcmt.lib to 'additional dependencies' and this yields all of these additional problems..

I have also looked at my runtime libraries and I am using a /MD build. My project has all of its libraries packaged with it and I can tell what this is referring to, but I can't seem to make my compiler happy.

Finally, I added this bit of code to my main program .cpp file and it worked...thought I am not sure why...

extern "C" {
FILE* _iob = NULL;
}




Any suggestions why this worked? This site has been very helpful with my project.

Thanks!
Posted
Updated 21-Jun-11 12:17pm
v3
Comments
Albert Holguin 21-Jun-11 18:28pm    
that worked because you essentially killed the reference... so the linker is happy... whether your program runs or not, that's a whole different story! ... :)
AndrewG1231 21-Jun-11 19:59pm    
...so, there is a chance that it will work perfectly fine?! I think this is good new.
Albert Holguin 13-Jul-11 11:59am    
There's a chance... but its playing with fire, you should really figure out what's wrong instead of patching the problem with a bad solution...
AndrewG1231 13-Jul-11 12:38pm    
I know, but I have to start somewhere...I am trying the solution below. Unfortunately, I won't know if the program runs correctly until I can find all the other libraries it is dependent on and change the code to exchange information with a different networking card. However, I have logged all my changes...thanks for all the help.

Try this link instead:

http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/4a1c9610-fa41-45f6-ad39-c9f6795be6f2/[^]

From that discussion it appears to be an issue of linking in a library that was either compiled with an earlier version of VS or which expects to link to the CRT statically. Assuming you can't recompile the library, can you link to the CRT statically? And does that fix the problem?

If not, it appears from the discussion that you should define _iob as:

extern "C" {
    FILE _iob[3] = {__iob_func()[0], __iob_func()[1], __iob_func()[2]};
}


Obviously if your code or the libarty doesn't actually use _iob then it doesn't matter how you define it. If, however, it is actually used, then the above definition (assuming it compiles and links) has a reasonable chance of actually working.
 
Share this answer
 
Comments
AndrewG1231 13-Jul-11 12:42pm    
It has been a little while, but thanks, this worked to compile...but I still have some things to do before I know if the program is working (such as change what networking card the program is using for information exchange with our DAC/ADC converter). Thanks for all the help everything compiled and linked fine. I will mark this as the solution if the program runs correctly.
 
Share this answer
 
Comments
AndrewG1231 20-Jun-11 15:38pm    
I looked at the link, and I am not linking against libc.lib..it is ignored. If I link against libcmt.lib I get tons of unresolved external errors, but if I link against msvcrt.lib the error does not disappear (the error mentioned above).
cariolihome 20-Jun-11 16:28pm    
__iob symbol located in libc.lib or in libcmt.lib, so You have to use one of them
AndrewG1231 21-Jun-11 17:58pm    
I tried both, and they generate additional errors...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900