I am getting LNK2019 error from linking C++ code with the standard library C++ library. I need to know which libraries contain the functions:
is_c_termination_complete,
__acrt_initialize,
__acrt_uninitialize,
__acrt_uninitialize_critical,
__acrt_thread_attach,
__acrt_thread_detach
to include it in the linking process.
I am writing code in C++ with MS Visual Studio community 2017 and Intel Parallel studio xe 2019 update 1 to be integrated in 3rd party software. The 3rd party software provides a "make" option to compile the object files and link them together.
Compilation works fine, linking provides an issue.
The 3rd party software provides an entry to provide basic linker options in the form of a variable. The default options are as follows:
link_sl='LINK', '/nologo', '/NOENTRY', '/INCREMENTAL:NO', '/subsystem:console', '/machine:AMD64',
' /NODEFAULTLIB:LIBC.LIB', '/NODEFAULTLIB:LIBCMT.LIB','/DEFAULTLIB:OLDNAMES.LIB', '/DEFAULTLIB:LIBIFCOREMD.LIB', '/DEFAULTLIB:LIBIFPORTMD.LIB', '/DEFAULTLIB:LIBMMD.LIB', '/DEFAULTLIB:kernel32.lib', '/DEFAULTLIB:user32.lib', '/DEFAULTLIB:advapi32.lib','/FIXED:NO', '/dll','/def:%E', '/out:%U', '%F', '%A', '%L', '%B',
'oldnames.lib', 'user32.lib', 'ws2_32.lib', 'netapi32.lib','advapi32.lib',
'msvcrt.lib', 'vcruntime.lib', 'ucrt.lib']
This gives the following 11 errors when linking:
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __vcrt_initialize referenced in function __scrt_initialize_crt
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __vcrt_uninitialize referenced in function __scrt_initialize_crt
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __vcrt_uninitialize_critical referenced in function __scrt_dllmain_uninitialize_critical
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __vcrt_thread_attach referenced in function __scrt_dllmain_crt_thread_attach
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __vcrt_thread_detach referenced in function __scrt_dllmain_crt_thread_attach
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol _is_c_termination_complete referenced in function __scrt_dllmain_uninitialize_c
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_initialize referenced in function __scrt_initialize_crt
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_uninitialize referenced in function __scrt_uninitialize_crt
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_uninitialize_critical referenced in function __scrt_dllmain_uninitialize_critical
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_thread_attach referenced in function __scrt_dllmain_crt_thread_attach
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_thread_detach referenced in function __scrt_dllmain_crt_thread_detach
Which basically means that I am not including all the necessary libraries.
I already found out that including the library 'libvcruntime.lib' in the options reduces the errors to 6. So, using:
link_sl='LINK', '/nologo', '/NOENTRY', '/INCREMENTAL:NO', '/subsystem:console', '/machine:AMD64',
' /NODEFAULTLIB:LIBC.LIB', '/NODEFAULTLIB:LIBCMT.LIB','/DEFAULTLIB:OLDNAMES.LIB', '/DEFAULTLIB:LIBIFCOREMD.LIB', '/DEFAULTLIB:LIBIFPORTMD.LIB', '/DEFAULTLIB:LIBMMD.LIB', '/DEFAULTLIB:kernel32.lib', '/DEFAULTLIB:user32.lib', '/DEFAULTLIB:advapi32.lib','/FIXED:NO', '/dll','/def:%E', '/out:%U', '%F', '%A', '%L', '%B',
'oldnames.lib', 'user32.lib', 'ws2_32.lib', 'netapi32.lib','advapi32.lib',
'msvcrt.lib', 'vcruntime.lib', 'ucrt.lib',**'libvcruntime.lib'**]
Results in:
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol _is_c_termination_complete referenced in function __scrt_dllmain_uninitialize_c
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_initialize referenced in function __scrt_initialize_crt
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_uninitialize referenced in function __scrt_uninitialize_crt
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_uninitialize_critical referenced in function __scrt_dllmain_uninitialize_critical
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_thread_attach referenced in function __scrt_dllmain_crt_thread_attach
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_thread_detach referenced in function __scrt_dllmain_crt_thread_detach
Which other libraries do I need to include in the linking process to resolve these?
I have encountered exactly the same problem when working within the framework provided by this 3rd party software. Although I cannot answer directly the question for finding the libraries containing _is_c_termination_complete, I realised it is still possible to make your code work: simply adding a /FORCE flag to your link_sl flag list.
According to MSVC official documentation:
The /FORCE option tells the linker to create a valid .exe file or DLL even if a symbol is referenced but not defined or is multiply defined.
Therefore, LNK2019 error messages will not stop the linker producing the dll library which is critical for the 3rd party software to run. The linker messages would look like:
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol _is_c_termination_complete referenced in function __scrt_dllmain_uninitialize_c
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_initialize referenced in function __scrt_initialize_crt
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_uninitialize referenced in function __scrt_uninitialize_crt
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_uninitialize_critical referenced in function __scrt_dllmain_uninitialize_critical
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_thread_attach referenced in function __scrt_dllmain_crt_thread_attach
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_thread_detach referenced in function __scrt_dllmain_crt_thread_detach
: warning LNK4088: image being generated due to /FORCE option; image may not run
msvcprt.lib(locale0_implib.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
This is certainly not a decant solution and is not guaranteed to be working in any case, however it worked for my codes at least.
I downloaded the most recent Zeranoe dev build here, included the header files to my code, placed extern "C" around the includes, since this is a C++ project and FFmpeg is a C library, and added the libs to Visual Studio as well, and I get this linker error:
1>Camera.obj : error LNK2019: unresolved external symbol _av_free referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_freep referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_frame_alloc referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_frame_free referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _avcodec_register_all referenced in function __catch$??0Camera#MicroDFV_Camera##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##0PAX#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _avcodec_alloc_context3 referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _avcodec_open2 referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _avcodec_close referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_init_packet referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_packet_unref referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _avcodec_find_encoder referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _avcodec_encode_video2 referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_opt_set referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_image_alloc referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>M:\Desktop\OpenCVTest\Debug\OpenCVTest.exe : fatal error LNK1120: 14 unresolved externals
Searching here and on Google I found many recommendations, such as to add #pragma comment(lib,...), and that the libs are static, so their order is important, and none of this helps.
So I scratched my head even more and realized that the Zeranoe build is made with MinGW-w64, so probably it won't link with Visual Studio. I inspected the lib using dumpbin and the symbols on the libs don't have the underscore, so I am pretty sure it won't work.
The other Zeranoe builds for Windows don't have libs, they are just plain .exe or exe + .dll.
Will I have to make my own VS2013 build of FFmpeg to link it, or is there some alternative way?
I have downloaded EasyHook 2.7 source and I try to compile it in my Visual Studio 2012 environment.
After solving a lot of warnings, I have found other warnings that I cannot solve, and these are:
1>error.obj : error LNK2019: unresolved external symbol _CoTaskMemAlloc#4 referenced in function _RtlGetLastErrorStringCopy#0
1>error.obj : error LNK2019: unresolved external symbol _CopyMemory#12 referenced in function _RtlGetLastErrorStringCopy#0
1>reloc.obj : error LNK2019: unresolved external symbol _ud_init#4 referenced in function _LhDisassembleInstruction#20
1>reloc.obj : error LNK2019: unresolved external symbol _ud_set_mode#8 referenced in function _LhDisassembleInstruction#20
1>reloc.obj : error LNK2019: unresolved external symbol _ud_set_input_buffer#12 referenced in function _LhDisassembleInstruction#20
1>reloc.obj : error LNK2019: unresolved external symbol _ud_set_syntax#8 referenced in function _LhDisassembleInstruction#20
1>reloc.obj : error LNK2019: unresolved external symbol _ud_disassemble#4 referenced in function _LhDisassembleInstruction#20
1>reloc.obj : error LNK2019: unresolved external symbol _ud_translate_intel#4 referenced in function _LhDisassembleInstruction#20
1>reloc.obj : error LNK2019: unresolved external symbol _ud_set_asm_buffer#12 referenced in function _LhDisassembleInstruction#20
1>C:\Users\Jaime Stuardo\Downloads\EasyHook-2.7.5159.0-Source\\Debug\x86\EasyHook32Drv.sys : fatal error LNK1120: 9 unresolved externals
What lib files I need to add so that the linker will not fail? notice that the first 2 functions belong to Windows API, so it is very curious it does not link.
Regards
Jaime
For the Windows functions, just look them up on MSDN. CoTaskMemAlloc says you need to link OLE32.LIB. CopyMemory says KERNEL32.LIB. The functions beginning with ud come from a library which Easyhook depends on: "EasyHook makes use of the udis86 library by Vivek.
I try to compile VC++ application and get the error message as below. Is there anyone who know what the library I may be missing? Any advice & suggestion are appreciated.
My Environment:
VC++ 2010
zlib-1.2.8
boost_1_57_0
icu
1>------ Build started: Project: paloserver, Configuration: Debug Win32 ------
1> Creating library C:/Users/a992788/Virtual Machines/Documents/Application/Palo/Palo 3.x Source Code/palo-code-546/molap/server/5.1/SourceCode/Debug/paloserver.lib and object C:/Users/a992788/Virtual Machines/Documents/Application/Palo/Palo 3.x Source Code/palo-code-546/molap/server/5.1/SourceCode/Debug/paloserver.exp
1>unzip.obj : error LNK2019: unresolved external symbol _inflateInit2_ referenced in function _unzOpenCurrentFile3
1>unzip.obj : error LNK2019: unresolved external symbol _inflate referenced in function _unzReadCurrentFile
1>unzip.obj : error LNK2019: unresolved external symbol _crc32 referenced in function _unzReadCurrentFile
1>zip.obj : error LNK2001: unresolved external symbol _crc32
1>unzip.obj : error LNK2019: unresolved external symbol _inflateEnd referenced in function _unzCloseCurrentFile
1>zip.obj : error LNK2019: unresolved external symbol _get_crc_table referenced in function _zipOpenNewFileInZip4_64
1>zip.obj : error LNK2019: unresolved external symbol _deflateInit2_ referenced in function _zipOpenNewFileInZip4_64
1>zip.obj : error LNK2019: unresolved external symbol _deflate referenced in function _zipWriteInFileInZip
1>zip.obj : error LNK2019: unresolved external symbol _deflateEnd referenced in function _zipCloseFileInZipRaw64
1>C:\Users\a992788\Virtual Machines\Documents\Application\Palo\Palo 3.x Source Code\palo-code-546\molap\server\5.1\SourceCode\Debug\paloserver.dll : fatal error LNK1120: 8 unresolved externals
Add reference to the zdll.lib in your source.
#pragma comment (lib, "zdll.lib")
I've tried to build M2Crypto (github) for win-amd64-py3.3:
python setup.py build --compiler msvc
And I've got an linker's unresolved external symbol errors (full log):
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:D:\Programy\Python33\libs /LIBPATH:D:\Programy\Python33\PCbuild\amd64 /LIBPATH:c:\pkg\lib ssleay32.lib libeay32.lib /EXPORT:PyInit___m2crypto build\temp.win-amd64-3.3\Release\SWIG/_m2crypto_wrap.obj /OUT:build\lib.win-amd64-3.3\M2Crypto\__m2crypto.pyd /IMPLIB:build\temp.win-amd64-3.3\Release\SWIG\__m2crypto.lib /MANIFESTFILE:build\temp.win-amd64-3.3\Release\SWIG\__m2crypto.pyd.manifest
_m2crypto_wrap.obj : warning LNK4197: export 'PyInit___m2crypto' specified multiple times; using first specification
Creating library build\temp.win-amd64-3.3\Release\SWIG\__m2crypto.lib and object build\temp.win-amd64-3.3\Release\SWIG\__m2crypto.exp
_m2crypto_wrap.obj : error LNK2019: unresolved external symbol PyString_AsStringAndSize referenced in function m2_PyString_AsStringAndSizeInt
_m2crypto_wrap.obj : error LNK2019: unresolved external symbol PyString_FromStringAndSize referenced in function bn_to_mpi
_m2crypto_wrap.obj : error LNK2019: unresolved external symbol PyInt_AS_LONG referenced in function asn1_integer_set
_m2crypto_wrap.obj : error LNK2019: unresolved external symbol PyBuffer_New referenced in function ec_key_get_public_der
_m2crypto_wrap.obj : error LNK2019: unresolved external symbol PyFile_AsFile referenced in function _wrap_err_print_errors_fp
_m2crypto_wrap.obj : error LNK2019: unresolved external symbol PyFile_Check referenced in function _wrap_err_print_errors_fp
_m2crypto_wrap.obj : error LNK2019: unresolved external symbol PyInstance_New referenced in function ssl_verify_callback
build\lib.win-amd64-3.3\M2Crypto\__m2crypto.pyd : fatal error LNK1120: 7 unresolved externals
What's going on? I'm using Win64 OpenSSL v1.0.1e. Do I need older libraries?
from the full log it looks like one first problem is that the compiler can't find the python c header files. Then the linker can't find the python library. Perhaps the options to cl.exe are not good (shouldn't it be /ID:\... instead of -ID:\...?) or you don't have the python header files installed.