Share via


can't static link to the C run-time library

Question

Wednesday, November 28, 2012 9:52 AM

I am building a .ax/.dll project using the VC2008 that link to some other .lib that are build using some old VC version, for example, vc2005.

I select the /MT option and add the libcmt.lib in the linker/input/additional dependencies. 

I select "_DllMainCRTStartup@12" as the entry point in the linker/advanced.

When I build the project, it reports the following errors:

1> Rebuild All started: Project: MxfSourceFilter, Configuration: Release Win32
1>Deleting intermediate and output files for project 'MxfSourceFilter', configuration 'Release|Win32'
1>Compiling...
1>wxutil.cpp
1>wxlist.cpp
1>wxdebug.cpp
1>.\baseclasses\wxdebug.cpp(11) : warning C4005: '_WINDLL' : macro redefinition
1>        command-line arguments :  see previous definition of '_WINDLL'
1>winutil.cpp
1>winctrl.cpp
1>vtrans.cpp
1>videoctl.cpp
1>transip.cpp
1>transfrm.cpp
1>sysclock.cpp
1>strmctl.cpp
1>source.cpp
1>seekpt.cpp
1>schedule.cpp
1>renbase.cpp
1>refclock.cpp
1>pullpin.cpp
1>pstream.cpp
1>outputq.cpp
1>mtype.cpp
1>Generating Code...
1>Compiling...
1>dllsetup.cpp
1>dllentry.cpp
1>ddmm.cpp
1>ctlutil.cpp
1>cprop.cpp
1>combase.cpp
1>amvideo.cpp
1>amfilter.cpp
1>amextra.cpp
1>Generating Code...
1>Compiling...
1>MxfReader.cpp
1>e:\prog\mxfsourcefilter3\MxfReader.h(36) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(157) : see declaration of 'strncpy'
1>e:\prog\mxfsourcefilter3\MxfReader.h(98) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(157) : see declaration of 'strncpy'
1>.\MxfReader.cpp(20) : warning C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(324) : see declaration of 'sscanf'
1>.\MxfReader.cpp(412) : warning C4018: '>' : signed/unsigned mismatch
1>.\MxfReader.cpp(441) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(237) : see declaration of 'fopen'
1>.\MxfReader.cpp(456) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(157) : see declaration of 'strncpy'
1>.\MxfReader.cpp(474) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(157) : see declaration of 'strncpy'
1>.\MxfReader.cpp(475) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(157) : see declaration of 'strncpy'
1>CMxfOutPinVideo.cpp
1>e:\prog\mxfsourcefilter3\MxfReader.h(36) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(157) : see declaration of 'strncpy'
1>e:\prog\mxfsourcefilter3\MxfReader.h(98) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(157) : see declaration of 'strncpy'
1>.\CMxfOutPinVideo.cpp(19) : warning C4995: 'strcpy': name was marked as #pragma deprecated
1>.\CMxfOutPinVideo.cpp(19) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(74) : see declaration of 'strcpy'
1>.\CMxfOutPinVideo.cpp(238) : warning C4995: 'strcpy': name was marked as #pragma deprecated
1>.\CMxfOutPinVideo.cpp(238) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(74) : see declaration of 'strcpy'
1>.\CMxfOutPinVideo.cpp(245) : warning C4995: 'strcpy': name was marked as #pragma deprecated
1>.\CMxfOutPinVideo.cpp(245) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(74) : see declaration of 'strcpy'
1>CMxfOutPinAudio.cpp
1>e:\prog\mxfsourcefilter3\MxfReader.h(36) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(157) : see declaration of 'strncpy'
1>e:\prog\mxfsourcefilter3\MxfReader.h(98) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(157) : see declaration of 'strncpy'
1>.\CMxfOutPinAudio.cpp(18) : warning C4995: 'strcpy': name was marked as #pragma deprecated
1>.\CMxfOutPinAudio.cpp(18) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(74) : see declaration of 'strcpy'
1>.\CMxfOutPinAudio.cpp(131) : warning C4244: 'argument' : conversion from 'LONGLONG' to 'long', possible loss of data
1>.\CMxfOutPinAudio.cpp(264) : warning C4995: 'strcpy': name was marked as #pragma deprecated
1>.\CMxfOutPinAudio.cpp(264) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(74) : see declaration of 'strcpy'
1>.\CMxfOutPinAudio.cpp(282) : warning C4995: 'strcpy': name was marked as #pragma deprecated
1>.\CMxfOutPinAudio.cpp(282) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(74) : see declaration of 'strcpy'
1>CFilterMxfSource.cpp
1>e:\prog\mxfsourcefilter3\MxfReader.h(36) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(157) : see declaration of 'strncpy'
1>e:\prog\mxfsourcefilter3\MxfReader.h(98) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(157) : see declaration of 'strncpy'
1>Generating Code...
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Linking...
1>   Creating library .\Release\mxfsource.lib and object .\Release\mxfsource.exp
1>MxfReader.obj : warning LNK4217: locally defined symbol _atoi imported in function "public: int __thiscall CMxfReader::Init(char const *)" (?Init@CMxfReader@@QAEHPBD@Z)
1>CMxfOutPinAudio.obj : error LNK2019: unresolved external symbol __imp__fclose referenced in function "public: virtual __thiscall CMxfOutPutAudio::~CMxfOutPutAudio(void)" (??1CMxfOutPutAudio@@UAE@XZ)
1>CMxfOutPinVideo.obj : error LNK2001: unresolved external symbol __imp__fclose
1>MxfReader.obj : error LNK2001: unresolved external symbol __imp__fclose
1>MxfReader.obj : error LNK2019: unresolved external symbol __imp__sscanf referenced in function "bool __cdecl keyStr2Bin(char const *,unsigned char *)" (?keyStr2Bin@@YA_NPBDPAE@Z)
1>MxfReader.obj : error LNK2019: unresolved external symbol __imp__strncpy referenced in function "public: int __thiscall CMxfReader::Init(char const *)" (?Init@CMxfReader@@QAEHPBD@Z)
1>MxfReader.obj : error LNK2019: unresolved external symbol __imp__strstr referenced in function "public: int __thiscall CMxfReader::GetWaveInfo(struct tWAVEFORMATEX &)" (?GetWaveInfo@CMxfReader@@QAEHAAUtWAVEFORMATEX@@@Z)
1>MxfReader.obj : error LNK2019: unresolved external symbol __imp__fgets referenced in function "public: int __thiscall CMxfReader::Init(char const *)" (?Init@CMxfReader@@QAEHPBD@Z)
1>MxfReader.obj : error LNK2019: unresolved external symbol __imp__feof referenced in function "public: int __thiscall CMxfReader::Init(char const *)" (?Init@CMxfReader@@QAEHPBD@Z)
1>MxfReader.obj : error LNK2019: unresolved external symbol __imp__fopen referenced in function "public: int __thiscall CMxfReader::Init(char const *)" (?Init@CMxfReader@@QAEHPBD@Z)
1>dllsetup.obj : error LNK2019: unresolved external symbol __imp___vsnprintf referenced in function "long __stdcall StringVPrintfWorkerA(char *,unsigned int,unsigned int *,char const *,char *)" (?StringVPrintfWorkerA@@YGJPADIPAIPBD0@Z)
1>winutil.obj : error LNK2001: unresolved external symbol __imp___vsnprintf
1>wxdebug.obj : error LNK2001: unresolved external symbol __imp___vsnprintf
1>wxutil.obj : error LNK2001: unresolved external symbol __imp___vsnprintf
1>pstream.obj : error LNK2019: unresolved external symbol __imp___vsnwprintf referenced in function "long __stdcall StringVPrintfWorkerW(wchar_t *,unsigned int,unsigned int *,wchar_t const *,char *)" (?StringVPrintfWorkerW@@YGJPA_WIPAIPB_WPAD@Z)
1>source.obj : error LNK2019: unresolved external symbol __imp___wtoi referenced in function "public: virtual long __stdcall CSource::FindPin(wchar_t const *,struct IPin * *)" (?FindPin@CSource@@UAGJPB_WPAPAUIPin@@@Z)
1>Release\mxfsource.ax : fatal error LNK1120: 10 unresolved externals
1>Build log was saved at "file://e:\prog\MxfSourceFilter3\Release\BuildLog.htm"
1>MxfSourceFilter - 16 error(s), 29 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

All the files that report error is the files in my project, not the files from other .libs.

Why the project can't link to the C runtime library?

 

All replies (2)

Wednesday, November 28, 2012 10:33 AM âś…Answered

The __imp__ prefix that shows up in linker errors my indicate that somehow you have _DLL set, as if you're trying to use the CRT DLL instead of the static one. That said I cannot reproduce this.

Why exactly are you adding libcmt.lib to the linker input? /MD should take care of this automatically.

What type is that old .lib? Static lib or DLL? What version of CRT is that .lib using?


Thursday, November 29, 2012 4:05 AM

OK, after I delete all _DLL defined in all files, I build the project successfully. Thank you very much.

I copy the setting that add the libcmt.lib to the linker input from the ffdshow setting.

The old .lib is .dll that should use vc2005 version crt.