Re: [libharu] Digest for libharu@googlegroups.com - 1 Message in 1 Topic

357 views
Skip to first unread message

karim duran

unread,
May 20, 2011, 6:08:02 PM5/20/11
to lib...@googlegroups.com
Hi, Bobby,

I suppose you use Microsoft C++ compiler which provides some ANSI / ISO C++ extensions. One of them, is to prefix with an underscore character some functions name in your built-in library.

For example, the documentation says there is a function named  "int foo(HPdf_Page page)". The function must be declared "extern C" in your code in order that the Linker can find it as a C function. It's the first point. If you have only the binary, i mean libhpdfs.lib, and this library has been compiled with a C compiler ( not a C++ compiler ) you have to declare the functions you use as "extern C".

If it's not done, sometimes, C++ compilers, prefix functions name with "_", and the linker considers it's another function symbol. Be also aware, that C++ compiler "decorates" functions names, not declared as "extern C". It can be another reason for the linker to not find it when resolving symbol substitution.

Linking C code and C++ code from *.lib and *.obj file must be setup in your IDE, even if the compiler don't complain.

In Google, type :
"extern C static linking" and  / or "C++ functions names decoration and Linker" and / or "mixing C and C++ code linker setup".

I hope it helps.

Karim Duran.

2011/5/18 <libharu...@googlegroups.com>

Group: http://groups.google.com/group/libharu/topics

    Bobby Reedy <Bobby...@infor.com> May 17 08:17AM -0400 ^
     
    Good day,
    Prior to now, I have used libHaru with Visual Studio 97 (VS5). We are moving everything to Visual Studio 2010. I am building static libs and they seem to build fine (zlib, libpng and libhpdf). However, I have the problem below when trying to link my application program. The deflate statements are part of zlib.
     
    Has anyone using VS 2010 encountered this type of error? I have spent over a day trying to figure out what I thought was a simple link lib problem, but I have not been able to resolve. Likewise I do not know if the problem is in my application or one of the lib builds.
     
    Any suggestions are greatly appreciated.
     
    Thanks... Bobby Reedy
     
     
    1>libhpdfs.lib(hpdf_streams.obj) : error LNK2019: unresolved external symbol _deflateEnd referenced in function _HPDF_Stream_WriteToStreamWithDeflate
     
    1>libhpdfs.lib(hpdf_streams.obj) : error LNK2019: unresolved external symbol _deflate referenced in function _HPDF_Stream_WriteToStreamWithDeflate
     
    1>libhpdfs.lib(hpdf_streams.obj) : error LNK2019: unresolved external symbol _deflateInit_ referenced in function _HPDF_Stream_WriteToStreamWithDeflate

     

--
---
libHaru.org development mailing list
To unsubscribe, send email to libharu-u...@googlegroups.com

karim duran

unread,
May 20, 2011, 6:16:10 PM5/20/11
to lib...@googlegroups.com
Precision, I believe that _deflate or _inflate functions are part from ZLIB library, not libhpdfs !!!!

Did you add zlib.lib to the library list used by the linker to build your binary ?

To do that, right click your project -> find build options -> compiler and linker options -> add zlib.lib in your library list.


I hope it helps.

Karim Duran.
karim...@gmail.com


2011/5/21 karim duran <karim...@gmail.com>

Bobby Reedy

unread,
May 23, 2011, 7:23:01 AM5/23/11
to lib...@googlegroups.com

Thank you Karim for your suggestions.  To restate the problem, the messages below came from the link step of my application program when trying to build static libs:

 

1>libhpdfs.lib(hpdf_streams.obj) : error LNK2019: unresolved external symbol _deflateEnd referenced in function _HPDF_Stream_WriteToStreamWithDeflate

1>libhpdfs.lib(hpdf_streams.obj) : error LNK2019: unresolved external symbol _deflate referenced in function _HPDF_Stream_WriteToStreamWithDeflate

1>libhpdfs.lib(hpdf_streams.obj) : error LNK2019: unresolved external symbol _deflateInit_ referenced in function _HPDF_Stream_WriteToStreamWithDeflate

 

This problem of unresolved externals with deflate functions (which are zlib functions) seem to be pretty common when you search the internet. Most all of the time the issue was what you describe as well as other common link errors such as using the /MT option versus /MD option.

 

After too many days spent on this issue, I found the problem.  I had to dig through the Haru and Zlib code to discover what was happening.

 

The issue was that I used the VS2010 SLN delivered in the zlib 1.2.5 (zlibvc.sln). Within it, there is a preprocessor option called ZLIB_WINAPI.  While I do not know all the details, this evidently caused the functions to be built differently than what the function calls in libHaru use (std libraries vs win api libs I think).

 

Once I removed ZLIB_WINAPI from the zlib build and rebuilt my application program, the link step worked properly.

 

I find that the move from an old MS VS environment to VS2010 is a big one. On one hand, the new visual studio is loaded with enhancements, but there is a price to pay in terms of complexity.  Things were much easier with simpler compile and link commands and make files.

 

We are also moving to updated compilers on several UNIX platforms.  I have yet to do this but I hope the transition is less cumbersome than it has been with the windows development environments.

 

Again, thanks for your suggestions and the time you took to look at it.

 

Bobby Reedy

Reply all
Reply to author
Forward
0 new messages