errors error LNK2001: unresolved external symbol _deflateEnd in VC++ - c++

I am using a external library of libharu-2.0.8, this is a open source pdf library.
This lib have a lib file called libhpdf.lib and few header files
I have written a simple code to use this library. I am getting following errors.
libhpdf.lib(hpdf_streams.obj) : error LNK2001: unresolved external symbol _deflateEnd
libhpdf.lib(hpdf_streams.obj) : error LNK2001: unresolved external symbol _deflate
libhpdf.lib(hpdf_streams.obj) : error LNK2001: unresolved external symbol deflateInit

They're calls to the zlib library functions, so you'll probably find that libhpdf has a dependency on that library.
In fact, if you go to http://libharu.sourceforge.net/, you'll see that you need both zlib and pnglib.
Quoting that page here:
In addition, ZLIB and PNGLIB are required when you want to use the features of compression and embedding PNG images. (In the case of Windows, static library files for several compilers are included in the package for WIndows. In the case of most of UNIX, these libraries are usually installed.)

You could find the files: libpng.lib and zlib.lib
already included in the package libharu_2_0_8_win32.zip in the directory:
libharu_2_0_8_win32\libharu-2.0.8\win32\msvc\
Simply add these files to your project and the errors disapear.

Related

Tensorflow config.pb.h causes unresolved external symbols error

I am trying to build the tensorflow C++ API (version 1.15.0, under Windows). I have managed to do so (after manually exporting some functions), but when used in the project I get the linker errors which are caused by the protobuf generated files config.pb.h located in the core include folders within TF.
error LNK2001: unresolved external symbol "const tensorflow::ConfigProto::`vftable'" (??_7ConfigProto#tensorflow##6B#)
error LNK2001: unresolved external symbol "const tensorflow::RunOptions::`vftable'" (??_7RunOptions#tensorflow##6B#)
This can't be resolved by manually adjusting the code before the lib is being built (as far as I know). Am I missing something obvious?

unresolved external symbol inflateEnd (and others) while using boost Zlib

I'm in the process of converting 32bit project to x64. In most cases it just means appending 64 to library paths (and eventually building those libraries for x64). Now I assume all libraries are already ready and the code is also x64 compatible. But I keep getting errors for boost zlib library, like these:
error LNK2019: unresolved external symbol inflateEnd
error LNK2019: unresolved external symbol inflate
error LNK2019: unresolved external symbol inflateInit_
error LNK2019: unresolved external symbol deflateEnd
error LNK2019: unresolved external symbol deflate
error LNK2001: unresolved external symbol "int const boost::iostreams::zlib::default_compression"
error LNK2001: unresolved external symbol "int const boost::iostreams::zlib::deflated"
error LNK2001: unresolved external symbol "int const boost::iostreams::zlib::default_strategy"
I enabled verbose mode for linker (in MS Visual Studio you do this by adding /VERBOSE:LIB to additional linker options). Thanks to that, I can see this output line:
Searching .\..\..\libs\boost145\stage\lib64\libboost_zlib-vc100-mt-gd-1_45.lib
That would imply that the library was found in the boost145\stage\lib64. So what should I be looking for now?
One strange thing is that file that defines the first group of missing symbols (those that are not within boost) has header files within the project, zlib.h and zconf.h. Maybe this is some hint? The zlib.h defines external symbols as:
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
Obvious question is: where the hell is lib file for this header file?
I had the same issue, to resolve the errors I download the source from zlib and built the x64 dlls/libs locally. There were a couple issues with solution file downloaded, fixes are described below.
Zlib 1.2.8 source code: http://zlib.net/zlib128.zip
Solution File for VS2012 is located at: zlib-1.2.8\contrib\vstudio\vc11\zlibvc.sln
Fixes:
Change:
<Command>cd ..\..\..\contrib\masmx64
bld_ml64.bat</Command>
to:
<Command>cd ..\..\contrib\masmx64
bld_ml64.bat</Command>
In zlibvc project properties -> Linker -> Advanced -> Image Has Safe Exception Handlers -> set to No (/SAFESEH:NO). Info about SAFESEH: Compiling libffi with VS2012 fails with fatal error LNK1281: Unable to generate SAFESEH image

Unresolved External Symbol for definitions with DATA in .def file

I'm trying to use ffmpeg libraries in a VC++ project. I added all the lib files and the headers and set up the properties for the compiler/linker including the .def file for the externals. All the libs/headers/defs come directly from ffmpeg windows 64bit builds. After all that I get errors like:
1>exports.def : error LNK2001: unresolved external symbol pp_help
1>exports.def : error LNK2001: unresolved external symbol swr_ffversion
1>exports.def : error LNK2001: unresolved external symbol sws_context_class
All of the definitions that are failing have a DATA keyword following them.
There are a total of 37 of them and all have the DATA keyword....
I'm new to the VS Compiler/Linker and I might have simply missed something. Any pointers would be greatly appreciated.
Why you define them in exports? You need to use exports.def only when you export something link. For ex. if you develop your own library.
Here you don't need to specify it in exports. You need to correctly link the lib and include headers.
The errors appear, because linker can't find the exported functions definitions. It thinks that you have declared and implemented those functions somewhere.

Why will I have link errors when invoking a library (building the library is successful) in C++

I have a question related to invoking a C++ library. The compilation of the library is successful. After that, the library is invoked by a normal executable program. However, several link errors occur.I give an example to illustrate my problem.
I have download an old version of TIFF library (version 3.6.1) and then compiled it to a static library: tiff.lib. After that I wrote an executable program for reading and writing TIFF files by invoking the library. However, the following errors appear:
2>tiff.lib(tif_jpeg.obj) : error LNK2001: unresolved external symbol __TIFFmalloc
2>tiff.lib(tif_lzw.obj) : error LNK2001: unresolved external symbol __TIFFmalloc
2>tiff.lib(tif_dirinfo.obj) : error LNK2001: unresolved external symbol __TIFFmalloc
2>tiff.lib(tif_luv.obj) : error LNK2001: unresolved external symbol __TIFFmalloc
2>tiff.lib(tif_pixarlog.obj) : error LNK2001: unresolved external symbol __TIFFmalloc
2>tiff.lib(tif_zip.obj) : error LNK2001: unresolved external symbol __TIFFmalloc
2>tiff.lib(tif_dirwrite.obj) : error LNK2001: unresolved external symbol __TIFFmalloc
2>tiff.lib(tif_write.obj) : error LNK2001: unresolved external symbol __TIFFmalloc
2>tiff.lib(tif_dirread.obj) : error LNK2001: unresolved external symbol __TIFFmalloc
I cannot understand why I will receive link errors as tiff.lib has been built successfully and it has also been linked successfully by my executable program. If something wrong with tiff.lib, I expect the link errors should appear during the compilation and link procedure when building the lib. Any ideas will be appreciated!
EDIT: I add some details in order to find the solution. tiff.lib is built as a static library, and when I use dumpbin.exe /exports tiff.lib to display all definitions exported in the library, the following message is given:
Dump of file tiff.lib
File Type: LIBRARY
Summary
3B8 .bss
9405 .data
D5640 .debug$S
C38 .debug$T
C4E .drectve
19E79 .rdata
84 .rtc$IMZ
84 .rtc$TMZ
3363E .text
It seems that no symbols are exported.
I think tiff.lib is C library and you are linking in c++. So I guess you will need to use extern "C" to include its header .h file.
extern "C"
{
#include<tiff.h>
}
Something like that above is just example. Also make sure you are setting correct calling convention in project property page of your c++ project
C/C++ ----------> Advanced ---------->Call Convention--->_cdecl(/Gd) //Set only if required
C/C++----------->Advanced------------>Compile As----->C++ Code(/TP)
Based on the discussions, I have come to realize that my program's error lies in the fact that some functions have not been defined correctly. It may happen that in some libraries the function may be declared in the head file with the keyword "extern". However, the implementation of the function is defined in another file, which could be excluded when building the library. Function calling conversion, as explained by #praks411, is another scenario, which you should consider when you meet with the same problem.

Why am I getting error LNK2001 when linking to zlib.lib?

I'm working on a project that already contains the gzip library as follows:
zlib\zlib.h
zlib\zlib.lib
zlib\zconf.h
I would like to use the gzip functions from this .lib but am getting the following errors:
Compress.cpp
Linking...
Compress.obj : error LNK2001: unresolved external symbol _gzclose
Compress.obj : error LNK2001: unresolved external symbol _gzerror
Compress.obj : error LNK2001: unresolved external symbol _gzwrite
Compress.obj : error LNK2001: unresolved external symbol _gzopen
.\Debug/files.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
The link settings include:
Object/library modules: zlib.lib
Project Options:
zlib.lib
In the file using the gzX() functions, it
#include "zlib/zlib.h"
What else needs to be done here to use these functions?
Thank You.
EDIT: Using Visual Studio 6.0 C++
EDIT2: It turned out the static library I was using had the gz() functions taken out of them. The header file still had them which was misleading.
I grabbed the one off here to get zlib to build in windows. If you did the same, you may have forgotten to #define ZLIB_WINAPI before including zlib.h
you also need to add zlib.lib to your project's libraries:
Project properties->Linker->Input->Additional Dependencies.
When the build stops, ctrl-click on the URL to see the more verbose form of the log and check the actual command line passed to the linker. That at least will tell you whether the option to link against zlib is being respected. You may get other useful diagnostic output. One possibility could be that the architecture is different (eg you're building x64 but the lib is x86)
It turned out the static library I was using had the gz() functions taken out of them. The header file still had them which was misleading.