Using zlib in Visual C++ project - windows

I've been struggling to compile my Visual C++ 2010 project with dependency of Zlib. I've got source code that worked on Linux and Mac OS X. Here's, where I have linker errors:
error LNK2019: unresolved external symbol _inflate#8 referenced in function...
error LNK2019: unresolved external symbol _inflateInit2_#16 referenced in function...
error LNK2019: unresolved external symbol _deflate#8 referenced in function...
error LNK2019: unresolved external symbol _deflateInit2_#32 referenced in function...
I've been finding solution for few days now, trying compiling Zlib different ways, but it is clear that I've missed something. Very similar question has been answered here, but not clearly enough for amateur like me. I would need step-by-step guide how to get it to work.
Thank you in advance.

If you have static libraries after building the Zlib, point them in your project at this location.Project properties -> Linker -> Input -> Additional dependencies. Give the absolute path.

Related

Use Nlopt Library in a Fortran project with Visual Studio on Windows

I have been using the NLopt library in my Fortran projects and I have no problem running it under Linux system. Now I just started using the Visual studio on Windows to write my Fortran programs. However, I am having some difficulties to use the NLopt library on Windows. I am using Visual Studio 2013 and Intel Parallel Studio XE 17 on my computer.
Here are what I have done and the problems that I have encountered:
I downloaded the Windows version (64 bit) of NLopt library from its website. Then I use the developer command prompt for VS to execute lib /def:libnlopt-0.def \MACHINE:x64 and it creates a .lib and .exp file under the same folder.
I created a Fortran project in Visual Studio with and use the code that was been working under Linux. In Visual Studio, I added the path to the .lib and .exp to "Additional Include Directories" and "Additional Library Directories" to the project property. I also added "libnlopt-0.lib" and "libnlopt-0.exp" to "Additional Dependencies".
When I compile the project, it fails with the errors:
1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_CREATE referenced in function MOD_NLOPT_mp_SUB_NLOPT
1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_FTOL_ABS referenced in function MOD_NLOPT_mp_SUB_NLOPT
1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_FTOL_REL referenced in function MOD_NLOPT_mp_SUB_NLOPT
1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_XTOL_ABS referenced in function MOD_NLOPT_mp_SUB_NLOPT
1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_XTOL_REL referenced in function MOD_NLOPT_mp_SUB_NLOPT
1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_LOWER_BOUNDS referenced in function MOD_NLOPT_mp_SUB_NLOPT
1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_UPPER_BOUNDS referenced in function MOD_NLOPT_mp_SUB_NLOPT
1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_MAX_OBJECTIVE referenced in function MOD_NLOPT_mp_SUB_NLOPT
1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_ADD_INEQUALITY_CONSTRAINT referenced in function MOD_NLOPT_mp_SUB_NLOPT
1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_OPTIMIZE referenced in function MOD_NLOPT_mp_SUB_NLOPT
1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_DESTROY referenced in function MOD_NLOPT_mp_SUB_NLOPT
Then I followed the suggestions [here] (http://nlopt-discuss.ab-initio.mit.narkive.com/M3vzZMYA/nlopt-linked-to-intel-fortran-compiler-for-windows) and added /names:lowercase to the command line and now it compiles fine but with one warning:
libnlopt-0.exp : warning LNK4070: /OUT:libnlopt-0.dll directive in .EXP differs from output filename 'x64\Release\baseline.exe'; ignoring directive
Although it compiles fine, I still cannot run my compiled code. When I run it, my computer tells me that This APP cannot run on your PC. To find a version for your PC, check with the software published. Then the command window shows Access denied and then the program stops.
I really do not know what I can do next to make my code work. I know there are many people use NLopt in Windows.
I just figured out the solution. For the second step above, I should only put "libnlopt-0.lib", but not "libnlopt-0.exp" to "Additional Dependencies" in Visual Studio project property. After that, I copied "libnlopt-0.dll" to the working directory of my program. Then my program can run without any problem!

Unresolved external symbol with zlib and libpng. Visual studio 2013

As I need to link to static C runtimes I decided to build all as static librarys in question with the same version of Visual Studio (2013) using the same Platform Toolset and Runtime libraries Multi-Threaded /MT
I am trying to get my application to link to a 3rd party game engine. This engine is built on top of libpng and zlib. libpng is also built on top of zlib.
So I build zlib from scratch into a static library.
I then build libpng and point it to the zlib as an additional dependency so zlib gets linked in to my libpng static library.
I then build my game engine linking to both libpng and zlib as additional dependencies. The linker removes the second zlib definition. So far all builds fine.
I then link my application just to my game engine static library. I get linker errors like:
2>libOxygine-vc120-mt-gd.lib(unzip.obj) : error LNK2001: unresolved external symbol _inflate
2>libOxygine-vc120-mt-gd.lib(pngrutil.obj) : error LNK2001: unresolved external symbol _inflate
2>libOxygine-vc120-mt-gd.lib(unzip.obj) : error LNK2001: unresolved external symbol _inflateEnd
2>libOxygine-vc120-mt-gd.lib(pngread.obj) : error LNK2001: unresolved external symbol _inflateEnd
2>libOxygine-vc120-mt-gd.lib(unzip.obj) : error LNK2001: unresolved external symbol _crc32
2>libOxygine-vc120-mt-gd.lib(png.obj) : error LNK2001: unresolved external symbol _crc32
2>libOxygine-vc120-mt-gd.lib(unzip.obj) : error LNK2001: unresolved external symbol _inflateInit2_
2>libOxygine-vc120-mt-gd.lib(png.obj) : error LNK2001: unresolved external symbol _adler32
2>libOxygine-vc120-mt-gd.lib(png.obj) : error LNK2001: unresolved external symbol _inflateReset
2>libOxygine-vc120-mt-gd.lib(pngrutil.obj) : error LNK2001: unresolved external symbol _inflateInit_
2>libOxygine-vc120-mt-gd.lib(pngwrite.obj) : error LNK2001: unresolved external symbol _deflateEnd
2>libOxygine-vc120-mt-gd.lib(pngwutil.obj) : error LNK2001: unresolved external symbol _deflateReset
2>libOxygine-vc120-mt-gd.lib(pngwutil.obj) : error LNK2001: unresolved external symbol _deflateInit2_
2>libOxygine-vc120-mt-gd.lib(pngwutil.obj) : error LNK2001: unresolved external symbol _deflate
It seems to be having a problem finding zlib but this has been linked into libpng, which in turn was linked into the game library libOxygine.
My application itself is not directly dependant on both zlib and libpng so I dont really want to have to link to them directly from my application as it should be all taken care of inside my game engine library libOxygine.
Thanks
If you used .vcxproj project from zlib package, it contains some bugs.
here is instruction for fixing them (i used zlibvc, not zlibstat):
http://www.tannerhelland.com/5076/compile-zlib-winapi-wapi-stdcall/
For fixing the unresolved symbols problem, open zlib project preferences,
then go to Configuration Properties -> C/C++ -> Preprocessor, and in the Preprocessor Definitions line remove “ZLIB_WINAPI;” (don’t forget to remove the trailing semicolon).
libpng depends upon zlib, so you must link libpng first, then zlib. From your error messages it appears that you have them reversed. For example, if you are using gcc to build and link, you need "-lpng -lz" on the commandline, not "-lz ... -lpng".

linking with openssl lib statically

I've build openssl manually (static libraries) following this guide now when I try to link my MFC test app with libeay32.lib I get following errors:
1>Linking...
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertFreeCertificateContext#4 referenced in function _capi_free_key
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertGetCertificateContextProperty#16 referenced in function _capi_get_prov_info
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertOpenStore#20 referenced in function _capi_open_store
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertFindCertificateInStore#24 referenced in function _capi_find_cert
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertEnumCertificatesInStore#8 referenced in function _capi_find_cert
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertCloseStore#8 referenced in function _capi_find_key
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertDuplicateCertificateContext#4 referenced in function _capi_load_ssl_client_cert
Any advice? Thanks in advance.
EDIT:
I’ve used OpenSSL 1.0.1t source code and Visual Studio 2008 command prompt for building 32 bit static libraries (I had no success with 1.0.2h version). My test app works fine when linking dynamically but I want to be able to link with static lib’s. I’m using OpenSSL for EVP Symmetric Encryption and Decryption
when I try to link my MFC test app with libeay32.lib I get following errors...
You need to configure with enable-capieng. Also see Compilation and Installation on the OpenSSL wiki and How to use CAPI engine in OpenSSL mailing list archive.
error LNK2019: unresolved external symbol __imp__CertFreeCertificateContext#4 referenced in function _capi_free_key
...
Once configured properly, you need to link against Windows' crypt32.lib library. See, for example, CertFreeCertificateContext functions. On Windows, it should be enough to add the following to your MSVC source file:
#pragma comment (lib, "crypt32");

Linking tesseract and opencv in Visual Studio 2013 on x64 bit machine

I'm trying to run a program based on tesseract and opencv on Visual Studio 2013. I have a x64 bit machine and the problem is when I run it under Win32 I got only opencv linking errors, however under x64 I got tesseract linking errors.
Here are some errors screenshots :
Tesseract Errors :
error LNK2001: unresolved external symbol pixDestroy
error LNK2001: unresolved external symbol pixReadTesseract
error LNK1120: 7 unresolved externals
Opencv Errors :
error LNK2001: unresolved external symbol _cvLoadImage
error LNK2001: unresolved external symbol _cvCreateImage
error LNK2001: unresolved external symbol _cvSaveImage
error LNK2001: unresolved external symbol _cvReleaseImage
error LNK1120: 4 unresolved externals
Thank you guys :-)
Your problem appears to be that you have 32bit build of Tesseract and 64bit build of OpenCV, and trying to use them both in the same program. That will not work -- you either need all 64bit libraries for a 64bit application, or all 32bit libraries for a 32bit application.
If you want to stick with OpenCV 3.1 (since the standard distribution package doesn't seem to contain 32bit binaries), then you have to go and build one of the libraries yourself. The older versions still had them.
Another option is to download this nuget package along with the associated redistributables package. Since the files are just ZIP files with a different extension, it is possible to extract all the headers, import libraries and DLLs manually.

CUDA: Getting linking error only in device emulation mode

I am compiling a dll which goes just fine unless I use the -deviceemu mode.
In this case I get several of the following linking errors:
CUDAKernel_ColourHist.obj : error LNK2019: unresolved external symbol
___cudaMutexOperation#4 referenced in function ___uAtomicAdd
1>CUDAKernel_1.obj : error LNK2001:
unresolved external symbol
___cudaMutexOperation#4 1>CUDAKernel_2.obj : error LNK2001:
unresolved external symbol
___cudaMutexOperation#4
Which led me to believe perhaps I wasn't linking the correct files, but I believe I am. I am using Visual Studio and any help woud be appreciated.
Fixed, I was using an older version of the libraries, linking with the newer libraries fixed the problem.

Resources