question

MaitiSouvik-6473 avatar image
0 Votes"
MaitiSouvik-6473 asked RLWA32-6355 commented

Visual Studio 2017 C++ Linking Error: LNK2019: unresolved external symbol __imp___stricmp referenced in function

Hello All - I'm working on upgrading a C++ project from Visual Studio 2008 to Visual Studio 2019. The conversion went well without any error. While trying to build the project under Release | Win32, getting one single error.

FileStream.obj : error LNK2019: unresolved external symbol imp_stricmp referenced in function "private: struct GUID _thiscall CFileStream::GetMediaSubType_Ext(char *,int)" (?GetMediaSubType_Ext@CFileStream@@AAE?AU_GUID@@PADH@Z)

I have included all the required libraries under Project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies. I have added the msvcrt.lib in it.

A little more details about the project -
Target Platform - Windows 10
Windows SDK Version - 10.0.17763.0
Configuration Type - Dynamic Library (.dll)
Code Generation - Multi-threaded (/MT)
Ignore All Default Libraries - Yes (/NODEFAULTLIB)

Thanks in advance for help. Please let me know in case of any additional queries.

c++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered RLWA32-6355 commented

I reproduced the issue by trying to build a small C application with two source files. The project properties were set to use the static CRT (/MT), but one of the source files had its properties set to use the DLL version of the CRT (/MD).

Consequently, it appears to me that the FileStream module has been compiled using /MD instead of /MT

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello,

Thanks for trying it out and really appreciate it. Your pointers did help me to resolve the issue. I checked at the file level (for FileStream.cpp) the configuration properties, found that the Runtime Library is set to /MT as expected. The problem was in the Preprocessor Definitions. It has got both _MT and _DLL. Once I removed the _DLL, the linking error is gone. The _DLL was causing it to use the DLL version of the CRT (/MD).

Thanks for your help again.

0 Votes 0 ·
RLWA32-6355 avatar image RLWA32-6355 MaitiSouvik-6473 ·

I'm happy to help. One additional thought to consider -- now that all the modules are compiled to use the same version of the UCRT you may be able to allow use of the default libraries instead of having to specify all of the libraries yourself.

0 Votes 0 ·
DavidLowndes-6766 avatar image
0 Votes"
DavidLowndes-6766 answered MaitiSouvik-6473 commented

Does your code use stricmp or _stricmp? It should probably use the latter name. See here.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for your response, David. We are using _tcsicmp which in turn using _stricmp. I should have given the code snippet.

0 Votes 0 ·
RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered RLWA32-6355 commented

Well, since the unresolved symbol is __imp__stricmp it seems that the linker wants to use an import library for the DLL version of the UCRT. However, the Code Generation option is /MT which leads me to believe that you have not passed any import libraries to the linker. You probably need to provide Ucrt.lib as a linker input.

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for your response. I'm already using libucrt.lib as additional dependencies. Putting the rest of it here as well. Hope this helps.

Winmm.lib
Wtsapi32.lib
Rpcrt4.lib
atls.lib
libcmt.lib
libvcruntime.lib
libvcruntimed.lib
msvcmrt.lib
msvcmrtd.lib
msvcurt.lib
msvcurtd.lib
msvcrt.lib
msvcrtd.lib
libucrt.lib
libucrtd.lib

0 Votes 0 ·
RLWA32-6355 avatar image RLWA32-6355 MaitiSouvik-6473 ·

Ucrt.lib is the import library for the ucrt dll. It is separate and distinct from libucrt lib see crt-library-features



1 Vote 1 ·

Thanks again for providing additional details. When I add ucrt.lib in addition with libucrt.lib, it's complaining about "fatal error LNK1169: one or more multiply defined symbols found".

4>Ucrt.lib(api-ms-win-crt-string-l1-1-0.dll) : error LNK2005: _strncmp already defined in libucrt.lib(strncmp.obj)
4>Ucrt.lib(api-ms-win-crt-string-l1-1-0.dll) : error LNK2005: strncpy already defined in libucrt.lib(strncpy.obj)
4>Ucrt.lib(api-ms-win-crt-heap-l1-1-0.dll) : error LNK2005: free already defined in libucrt.lib(free.obj)
4>Ucrt.lib(api-ms-win-crt-heap-l1-1-0.dll) : error LNK2005: malloc already defined in libucrt.lib(malloc.obj)
4>Ucrt.lib(api-ms-win-crt-stdio-l1-1-0.dll) : error LNK2005:
stdio_common_vsprintf already defined in libucrt.lib(output.obj)
4>Ucrt.lib(api-ms-win-crt-stdio-l1-1-0.dll) : error LNK2005:
_stdio_common_vswprintf already defined in libucrt.lib(output.obj)

If I remove libucrt.lib, then I'm getting different set of errors from libcmt.lib.

0 Votes 0 ·
Show more comments
RLWA32-6355 avatar image RLWA32-6355 MaitiSouvik-6473 ·

Additionally, you should be linking with libraries that are appropriate for your build configuration, either release or debug.

1 Vote 1 ·

I'm now using the release version of the libs. Thanks for the suggestions.

0 Votes 0 ·
JeanineZhang-MSFT avatar image
0 Votes"
JeanineZhang-MSFT answered MaitiSouvik-6473 commented

Hi,

I suggest you should check if the platform and configuration settings are consistent with the build time (Release | Win32).

137604-image.png

Best Regards,

Jeanine



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (2.6 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks, Jeanine for your response. I did confirm that both the platform and configuration settings are consistent with the build time (Release | Win32).

0 Votes 0 ·