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".
Related
PyTorch extensions seem to be experimental.
There is a work around described here:
https://pytorch.org/docs/stable/notes/windows.html#extension
I converted to cpp and added the libs as described:
from torch.utils.ffi import create_extension
ffi = create_extension(
'_ext.nms',
headers=headers,
sources=sources,
define_macros=defines,
relative_to=__file__,
with_cuda=with_cuda,
extra_objects=extra_objects,
libraries=["cudart","_C"]
)
It compiles ok, however, I am still getting a lot of unresolved external symbols from the linker:
nms.obj : error LNK2001: unresolved external symbol __imp_THFloatTensor_data
nms.obj : error LNK2001: unresolved external symbol __imp_THByteTensor_fill
nms.obj : error LNK2001: unresolved external symbol __imp_THExpm1
[...]
The _C.lib does not seem to contain the TH... symbols (checked with dumpbin _C.lib /ALL), and I can't find any libTH.lib or similar to link.
Where do I find the right library?
Is there any chance to do this on Windows?
I am compiling OpenBLAS with Visual Studio 2017, using this tutorial: https://github.com/xianyi/OpenBLAS/wiki/How-to-use-OpenBLAS-in-Microsoft-Visual-Studio#cmake-and-visual-studio. It works perfectly. However, when I try to link to a project that is using OpenBLAS, I have errors during the link.
error LNK2019: unresolved external symbol spotrf_
error LNK2019: unresolved external symbol dpotrf_
error LNK2019: unresolved external symbol spotri_
error LNK2019: unresolved external symbol dpotri_
error LNK2019: unresolved external symbol sgeqrf_
error LNK2019: unresolved external symbol dgeqrf_
error LNK2019: unresolved external symbol sorgqr_
error LNK2019: unresolved external symbol dorgqr_
error LNK2019: unresolved external symbol ssyevd_
error LNK2019: unresolved external symbol dsyevd_
This project was working perfectly with the downloaded binary version of OpenBLAS. The only notable difference is, I changed the include path to the one generated by CMake. And instead of linking to libopenblas.dll.a, I link to openblas.lib, which should be a more Visual-Studio-friendly way of linking...
I noticed that all these functions seems to come from Fortran files. Could that be the reason? And since OpenBLAS seems to be compilable with Visual Studio, how to fix the problem?
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");
I built ffmpeg 1.2.1 as a static lib - x64, debug. And I tried to open one of my older projects that links against it. After modifying some changed APIs and similar in my source, it compiled fine, but I have major problems with linking.
EDITED: the complete latest build output:
1>libavformat.a(mov.o) : error LNK2019: unresolved external symbol __imp__gmtime64 referenced in function mov_read_mvhd
1>libavutil.a(parseutils.o) : error LNK2001: unresolved external symbol __imp__gmtime64
1>libavformat.a(os_support.o) : error LNK2019: unresolved external symbol __imp__wsopen referenced in function ff_win32_open
1>libavcodec.a(pthread.o) : error LNK2019: unresolved external symbol __imp__beginthreadex referenced in function ff_thread_init
1>libavcodec.a(frame_thread_encoder.o) : error LNK2001: unresolved external symbol __imp__beginthreadex
1>libavutil.a(parseutils.o) : error LNK2019: unresolved external symbol __imp__localtime64 referenced in function av_parse_time
1>libavutil.a(parseutils.o) : error LNK2019: unresolved external symbol __imp__time64 referenced in function av_parse_time
1>libavutil.a(parseutils.o) : error LNK2019: unresolved external symbol __imp__mktime64 referenced in function av_parse_time
1>libmingwex.a(lib64_libmingwex_a-mingw_output_format.o) : error LNK2019: unresolved external symbol __mingw_get_msvcrt_handle referenced in function __mingw_set_output_format
1>libmingwex.a(lib64_libmingwex_a-mingw_get_codepage.o) : error LNK2001: unresolved external symbol __mingw_get_msvcrt_handle
What am I doing wrong? What am I missing here?
Does ffmpeg even work today on Windows platform as a static lib, or it becomes less functional on Windows with each new version?
First 8 errors could be solved by manually inserting
#define _CRTIMP
in some files. This will prevent incorrect use of declspec(__dllimport). We are building a static lib, not a DLL, so it shouldn't be there. I also tried using --extra-cflags='-D_CRTIMP' while running configure before building ffmpeg, but it brakes the build totally. So, manual way is the only way.
The last 2 errors are total bitch:
libmingwex.a(lib64_libmingwex_a-mingw_output_format.o) : error LNK2019: unresolved external symbol __mingw_get_msvcrt_handle referenced in function __mingw_set_output_format
1>libmingwex.a(lib64_libmingwex_a-mingw_get_codepage.o) : error LNK2001: unresolved external symbol __mingw_get_msvcrt_handle
I found these symbols in libmingw32.a (if I remember correctly). But, when I link it, I have conflicts with LIBCMTD.lib. Removing the LIBCMTD.lib creates tons of unresolved externals.So, I would say that today we are not able to build ffmpeg as static x64 lib on Windows. It was in a way expected, because each new version was less Windows friendly.
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.