Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

Visual Studio - /NODEFAULTLIB 옵션 설정 후 수동으로 추가해야 할 library

간단하게 Visual C++ Console Application 프로젝트를 만들고, 소스코드를 다음과 같이 구성합니다.

class CTest
{
};

int main()
{
    CTest* ptr = new CTest();
}

이 상태에서 프로젝트 속성 창을 통해 "Yes (/NODEFAULTLIB)" 옵션을 주면,

nodefaultlib_1.png

이제 빌드 시 다음과 같은 오류가 발생합니다.

Error   LNK2019 unresolved external symbol "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) referenced in function main ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol strlen referenced in function "public: static unsigned __int64 __cdecl std::_Narrow_char_traits<char,int>::length(char const * const)" (?length@?$_Narrow_char_traits@DH@std@@SA_KQEBD@Z)  ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "bool __cdecl std::uncaught_exception(void)" (?uncaught_exception@std@@YA_NXZ) referenced in function "public: __cdecl std::basic_ostream<char,struct std::char_traits<char> >::sentry::~sentry(void)" (??1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@XZ)  ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: bool __cdecl std::ios_base::good(void)const " (__imp_?good@ios_base@std@@QEBA_NXZ) referenced in function "public: __cdecl std::basic_ostream<char,struct std::char_traits<char> >::sentry::sentry(class std::basic_ostream<char,struct std::char_traits<char> > &)" (??0sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@AEAV12@@Z)  ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: int __cdecl std::ios_base::flags(void)const " (__imp_?flags@ios_base@std@@QEBAHXZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)  ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __int64 __cdecl std::ios_base::width(void)const " (__imp_?width@ios_base@std@@QEBA_JXZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z) ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __int64 __cdecl std::ios_base::width(__int64)" (__imp_?width@ios_base@std@@QEAA_J_J@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)  ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: int __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" (__imp_?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAAHD@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)  ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __int64 __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,__int64)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAA_JPEBD_J@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)    ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: void __cdecl std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (__imp_?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QEAAXH_N@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z) ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > * __cdecl std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " (__imp_?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBAPEAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) referenced in function "public: __cdecl std::basic_ostream<char,struct std::char_traits<char> >::sentry::sentry(class std::basic_ostream<char,struct std::char_traits<char> > &)" (??0sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@AEAV12@@Z)    ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::basic_streambuf<char,struct std::char_traits<char> > * __cdecl std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " (__imp_?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBAPEAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)    ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: char __cdecl std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " (__imp_?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBADXZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)  ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: void __cdecl std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (__imp_?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAXXZ) referenced in function "public: __cdecl std::basic_ostream<char,struct std::char_traits<char> >::sentry::~sentry(void)" (??1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@XZ)   ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (__imp_?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@XZ) referenced in function "public: __cdecl std::basic_ostream<char,struct std::char_traits<char> >::sentry::sentry(class std::basic_ostream<char,struct std::char_traits<char> > &)" (??0sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@AEAV12@@Z) ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol _RTC_CheckStackVars referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)    ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2001 unresolved external symbol _RTC_InitBase    ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2001 unresolved external symbol _RTC_Shutdown    ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2001 unresolved external symbol __CxxFrameHandler4   ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2001 unresolved external symbol __GSHandlerCheck_EH4 ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol __security_check_cookie referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)    ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > std::cout" (__imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A) referenced in function main ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2019 unresolved external symbol __security_cookie referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)  ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2001 unresolved external symbol mainCRTStartup   ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\LINK    1   
Error   LNK1120 24 unresolved externals ConsoleApplication1 C:\temp\ConsoleApplication1\x64\Debug\ConsoleApplication1.exe   1   

오류를 보면, 가장 기본적인 new 연산자조차 없는 걸로 나옵니다.

LNK2019 unresolved external symbol "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) referenced in function main 

예전에 이에 대해 정리한 적이 있는데요,

MASM + CRT 함수를 사용하는 경우 발생하는 컴파일 오류 정리
; https://www.sysnet.pe.kr/2/0/13183

따라서 위와 같은 소스코드에서는 다음의 3개 library를 "Additional Dependencies"추가하면,

nodefaultlib_2.png

  • vcruntime.lib
  • ucrt.lib
  • libcmt.lib

정상적으로 빌드가 됩니다.




자, 그럼 소스코드에 stl을 사용해 볼까요? ^^

#include <iostream>

class CTest
{
};

int main()
{
    std::cout << "Hello World!\n";

    CTest* ptr = new CTest();
}

이제는 또다시 링커 에러가 발생하는데요,

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "bool __cdecl std::uncaught_exception(void)" (?uncaught_exception@std@@YA_NXZ) referenced in function "public: __cdecl std::basic_ostream<char,struct std::char_traits<char> >::sentry::~sentry(void)" (??1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@XZ)  ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: bool __cdecl std::ios_base::good(void)const " (__imp_?good@ios_base@std@@QEBA_NXZ) referenced in function "public: __cdecl std::basic_ostream<char,struct std::char_traits<char> >::sentry::sentry(class std::basic_ostream<char,struct std::char_traits<char> > &)" (??0sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@AEAV12@@Z)  ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: int __cdecl std::ios_base::flags(void)const " (__imp_?flags@ios_base@std@@QEBAHXZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)  ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __int64 __cdecl std::ios_base::width(void)const " (__imp_?width@ios_base@std@@QEBA_JXZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z) ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __int64 __cdecl std::ios_base::width(__int64)" (__imp_?width@ios_base@std@@QEAA_J_J@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)  ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: int __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" (__imp_?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAAHD@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)  ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __int64 __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,__int64)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAA_JPEBD_J@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)    ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: void __cdecl std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (__imp_?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QEAAXH_N@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z) ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > * __cdecl std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " (__imp_?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBAPEAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) referenced in function "public: __cdecl std::basic_ostream<char,struct std::char_traits<char> >::sentry::sentry(class std::basic_ostream<char,struct std::char_traits<char> > &)" (??0sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@AEAV12@@Z)    ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::basic_streambuf<char,struct std::char_traits<char> > * __cdecl std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " (__imp_?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBAPEAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)    ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: char __cdecl std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " (__imp_?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBADXZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)  ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: void __cdecl std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (__imp_?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAXXZ) referenced in function "public: __cdecl std::basic_ostream<char,struct std::char_traits<char> >::sentry::~sentry(void)" (??1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@XZ)   ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (__imp_?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@XZ) referenced in function "public: __cdecl std::basic_ostream<char,struct std::char_traits<char> >::sentry::sentry(class std::basic_ostream<char,struct std::char_traits<char> > &)" (??0sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@AEAV12@@Z) ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > std::cout" (__imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A) referenced in function main ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj    1   
Error   LNK1120 14 unresolved externals ConsoleApplication1 E:\cloud_drive\Dropbox\articles\waveDest_compile\ConsoleApplication1\x64\Debug\ConsoleApplication1.exe  1   

이에 대해서는 다음의 문서에 따라,

C runtime (CRT) and C++ standard library (STL) .lib files
; https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170#c-standard-library-stl-lib-files

"C++ standard library (STL) .lib files"를 위해 (문서에 나오는 것 중에서, 여기서는) msvcprt.lib와 링크하도록 설정을 추가합니다. 따라서, 대부분의 Visual C++ 프로젝트라면 다음의 4개 lib를 추가하면 됩니다.

  • vcruntime.lib
  • ucrt.lib
  • libcmt.lib
  • msvcprt.lib

위의 목록은 Release 빌드용이므로 디버깅을 위해서 'd' 글자가 붙은 버전을 사용할 수 있습니다.

  • vcruntimed.lib
  • ucrtd.lib
  • libcpmtd.lib
  • msvcprtd.lib

참고로 필요한 lib 파일명은 Visual Studio의 버전에 따라 달라질 수 있으므로 문서 링크에 있는 "view=msvc-170" 값에 따라 적절하게 찾아야 합니다.




libcmt.lib 없이 vcruntime.lib, ucrt.lib만 포함시키면 이렇게 링커 오류가 발생합니다.

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) referenced in function main ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2001 unresolved external symbol _RTC_InitBase    ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2001 unresolved external symbol _RTC_Shutdown    ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1   
Error   LNK2001 unresolved external symbol mainCRTStartup   ConsoleApplication1 C:\temp\ConsoleApplication1\ConsoleApplication1\LINK    1   
Error   LNK1120 4 unresolved externals  ConsoleApplication1 C:\temp\ConsoleApplication1\x64\Debug\ConsoleApplication1.exe   1   

또한, "$(CoreLibraryDependencies)"로 추가되는 라이브러리들은 다음과 같습니다.

kernel32.lib
user32.lib
gdi32.lib
winspool.lib
comdlg32.lib
advapi32.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
odbc32.lib
odbccp32.lib




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 4/6/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  8  9  10  11  12  13  14  [15]  ...
NoWriterDateCnt.TitleFile(s)
13217정성태1/13/20233738디버깅 기술: 185. windbg - 64비트 운영체제에서 작업 관리자로 뜬 32비트 프로세스의 덤프를 sos로 디버깅하는 방법
13216정성태1/12/20234008디버깅 기술: 184. windbg - 32비트 프로세스의 메모리 덤프인 경우 !peb 명령어로 나타나지 않는 환경 변수
13215정성태1/11/20235308Linux: 56. 리눅스 - /proc/pid/stat 정보를 이용해 프로세스의 CPU 사용량 구하는 방법 [1]
13214정성태1/10/20235112.NET Framework: 2087. .NET 6부터 SourceGenerator와 통합된 System.Text.Json [1]파일 다운로드1
13213정성태1/9/20234577오류 유형: 836. docker 이미지 빌드 시 "RUN apt install ..." 명령어가 실패하는 이유
13212정성태1/8/20234374기타: 85. 단정도/배정도 부동 소수점의 정밀도(Precision)에 따른 형변환 손실
13211정성태1/6/20234418웹: 42. (https가 아닌) http 다운로드를 막는 웹 브라우저
13210정성태1/5/20233592Windows: 219. 윈도우 x64의 경우 0x00000000`7ffe0000 아래의 주소는 왜 사용하지 않을까요?
13209정성태1/4/20233390Windows: 218. 왜 윈도우에서 가상 메모리 공간은 64KB 정렬이 된 걸까요?
13208정성태1/3/20233355.NET Framework: 2086. C# - Windows 운영체제의 2MB Large 페이지 크기 할당 방법파일 다운로드1
13207정성태12/26/20223693.NET Framework: 2085. C# - gpedit.msc의 "User Rights Assignment" 특권을 코드로 설정/해제하는 방법파일 다운로드1
13206정성태12/24/20223889.NET Framework: 2084. C# - GetTokenInformation으로 사용자 SID(Security identifiers) 구하는 방법 [3]파일 다운로드1
13205정성태12/24/20224319.NET Framework: 2083. C# - C++과의 연동을 위한 구조체의 fixed 배열 필드 사용 (2)파일 다운로드1
13204정성태12/22/20223588.NET Framework: 2082. C# - (LSA_UNICODE_STRING 예제로) CustomMarshaler 사용법파일 다운로드1
13203정성태12/22/20223662.NET Framework: 2081. C# Interop 예제 - (LSA_UNICODE_STRING 예제로) 구조체를 C++에 전달하는 방법파일 다운로드1
13202정성태12/21/20224007기타: 84. 직렬화로 설명하는 Little/Big Endian파일 다운로드1
13201정성태12/20/20224608오류 유형: 835. PyCharm 사용 시 C 드라이브 용량 부족
13200정성태12/19/20223543오류 유형: 834. 이벤트 로그 - SSL Certificate Settings created by an admin process for endpoint
13199정성태12/19/20223800개발 환경 구성: 656. Internal Network 유형의 스위치로 공유한 Hyper-V의 VM과 호스트가 통신이 안 되는 경우
13198정성태12/18/20223728.NET Framework: 2080. C# - Microsoft.XmlSerializer.Generator 처리 없이 XmlSerializer 생성자를 예외 없이 사용하고 싶다면?파일 다운로드1
13197정성태12/17/20223619.NET Framework: 2079. .NET Core/5+ 환경에서 XmlSerializer 사용 시 System.IO.FileNotFoundException 예외 발생하는 경우파일 다운로드1
13196정성태12/16/20223754.NET Framework: 2078. .NET Core/5+를 위한 SGen(Microsoft.XmlSerializer.Generator) 사용법
13195정성태12/15/20224354개발 환경 구성: 655. docker - bridge 네트워크 모드에서 컨테이너 간 통신 시 --link 옵션 권장 이유
13194정성태12/14/20224314오류 유형: 833. warning C4747: Calling managed 'DllMain': Managed code may not be run under loader lock파일 다운로드1
13193정성태12/14/20224419오류 유형: 832. error C7681: two-phase name lookup is not supported for C++/CLI or C++/CX; use /Zc:twoPhase-
13192정성태12/13/20224383Linux: 55. 리눅스 - bash shell에서 실수 연산
1  2  3  4  5  6  7  8  9  10  11  12  13  14  [15]  ...