Reputation: 602
I am attempting to port some C++ files which run under Google Test (gtest) from a Linux development environment to a Windows development environment. I haven't used Visual Studio in about ten years and am more of a Linux guy so this may be a very ignorant question. How can I compile and link Google Test using the cl.exe compile of Visual Studio 2019?
I have a simple example test.cpp file:
#include "gtest/gtest.h"
TEST(TestCaseName, TestName)
{
EXPECT_EQ(1, 1);
EXPECT_TRUE(true);
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
}
I try to compile it with something like:
cl.exe /I "C:\gtest\include" main.cpp gtest.lib gtest_main.lib
This compiles for me but it does not link. I get 26 unresolved externals, such as __imp___dup, __imp___dup2, and __imp___creat. Is there something I am missing from my compile line?
The full output is as follows, but it may be messy as I am probably making an obvious mistake:
test.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\ostream(746): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
C:\Users\dfarm\Source\Repos\Sample-Test1\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.3\build\native\include\gtest/gtest-message.h(106): note: see reference to function template instantiation 'std::basic_ostream<char,std::char_traits<char> &std::operator <<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char> &,const char *)' being compiled
Microsoft (R) Incremental Linker Version 14.28.29914.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
gtest.lib
gtest_main.lib
gtest.lib(gtest-all.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: struct _Cvtvec __thiscall std::_Locinfo::_Getcvt(void)const " (?_Getcvt@_Locinfo@std@@QBE?AU_Cvtvec@@XZ) already defined in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: unsigned short const * __thiscall std::_Locinfo::_W_Getdays(void)const " (?_W_Getdays@_Locinfo@std@@QBEPBGXZ) already defined in libcpmt.lib(wlocale.obj)
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: unsigned short const * __thiscall std::_Locinfo::_W_Getmonths(void)const " (?_W_Getmonths@_Locinfo@std@@QBEPBGXZ) already defined in libcpmt.lib(wlocale.obj)
msvcprt.lib(MSVCP140.dll) : error LNK2005: "protected: __thiscall std::basic_streambuf<char,struct std::char_traits<char >::basic_streambuf<char,struct std::char_traits<char >(void)" (??0?$basic_streambuf@DU?$char_traits@D@std@@@std@@IAE@XZ) already defined in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: virtual __thiscall std::basic_streambuf<char,struct std::char_traits<char >::~basic_streambuf<char,struct std::char_traits<char >(void)" (??1?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAE@XZ) already defined in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHD@Z) already defined in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "protected: char * __thiscall std::basic_streambuf<char,struct std::char_traits<char >::_Pninc(void)" (?_Pninc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IAEPADXZ) already defined in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: virtual __thiscall std::basic_ios<char,struct std::char_traits<char >::~basic_ios<char,struct std::char_traits<char >(void)" (??1?$basic_ios@DU?$char_traits@D@std@@@std@@UAE@XZ) already defined in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: void __thiscall std::basic_ios<char,struct std::char_traits<char >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z) already defined in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: char __thiscall std::basic_ios<char,struct std::char_traits<char >::widen(char)const " (?widen@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDD@Z) already defined in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "protected: __thiscall std::basic_ios<char,struct std::char_traits<char >::basic_ios<char,struct std::char_traits<char >(void)" (??0?$basic_ios@DU?$char_traits@D@std@@@std@@IAE@XZ) already defined in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: void __thiscall std::basic_ostream<char,struct std::char_traits<char >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char & __thiscall std::basic_ostream<char,struct std::char_traits<char >::operator<<(int)" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z) already defined in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char & __thiscall std::basic_ostream<char,struct std::char_traits<char >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ) already defined in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: __thiscall std::basic_iostream<char,struct std::char_traits<char >::basic_iostream<char,struct std::char_traits<char >(class std::basic_streambuf<char,struct std::char_traits<char *)" (??0?$basic_iostream@DU?$char_traits@D@std@@@std@@QAE@PAV?$basic_streambuf@DU?$char_traits@D@std@@@1@@Z) already defined in test.obj
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: virtual __thiscall std::basic_iostream<char,struct std::char_traits<char >::~basic_iostream<char,struct std::char_traits<char >(void)" (??1?$basic_iostream@DU?$char_traits@D@std@@@std@@UAE@XZ) already defined in test.obj
Creating library test.lib and object test.exp
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4217: symbol '__invalid_parameter_noinfo_noreturn' defined in 'libucrt.lib(invalid_parameter.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"public: class testing::Message & __thiscall testing::Message::operator<<<class testing::Message>(class testing::Message const &)" (??$?6VMessage@testing@@@Message@testing@@QAEAAV01@ABV01@@Z)'
LINK : warning LNK4217: symbol '_calloc' defined in 'libucrt.lib(calloc.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"wchar_t * __cdecl std::_Maklocwcs(wchar_t const *)" (?_Maklocwcs@std@@YAPA_WPB_W@Z)'
LINK : warning LNK4217: symbol '_free' defined in 'libucrt.lib(free.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"public: __thiscall testing::internal::RE::~RE(void)" (??1RE@internal@testing@@QAE@XZ)'
LINK : warning LNK4217: symbol '_malloc' defined in 'libucrt.lib(malloc.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"private: void __thiscall testing::internal::RE::Init(char const *)" (?Init@RE@internal@testing@@AAEXPBD@Z)'
LINK : warning LNK4217: symbol '__errno' defined in 'libucrt.lib(errno.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"bool __cdecl testing::internal::ParseNaturalNumber<int>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char const &,int *)" (??$ParseNaturalNumber@H@internal@testing@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAH@Z)'
LINK : warning LNK4217: symbol '_exit' defined in 'libucrt.lib(exit.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"int __cdecl testing::internal::Int32FromEnvOrDie(char const *,int)" (?Int32FromEnvOrDie@internal@testing@@YAHPBDH@Z)'
LINK : warning LNK4217: symbol '__exit' defined in 'libucrt.lib(exit.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"protected: virtual void __thiscall testing::internal::DeathTestImpl::Abort(enum testing::internal::DeathTest::AbortReason)" (?Abort@DeathTestImpl@internal@testing@@MAEXW4AbortReason@DeathTest@23@@Z)'
LINK : warning LNK4217: symbol '_abort' defined in 'libucrt.lib(abort.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"void __cdecl testing::internal::posix::Abort(void)" (?Abort@posix@internal@testing@@YAXXZ)'
LINK : warning LNK4217: symbol '__set_abort_behavior' defined in 'libucrt.lib(abort.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"public: int __thiscall testing::UnitTest::Run(void)" (?Run@UnitTest@testing@@QAEHXZ)'
LINK : warning LNK4217: symbol '__set_error_mode' defined in 'libucrt.lib(set_error_mode.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"public: int __thiscall testing::UnitTest::Run(void)" (?Run@UnitTest@testing@@QAEHXZ)'
LINK : warning LNK4217: symbol '_strtol' defined in 'libucrt.lib(strtox.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"bool __cdecl testing::internal::ParseInt32(class testing::Message const &,char const *,int *)" (?ParseInt32@internal@testing@@YA_NABVMessage@2@PBDPAH@Z)'
LINK : warning LNK4217: symbol '__strtoui64' defined in 'libucrt.lib(strtox.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"bool __cdecl testing::internal::ParseNaturalNumber<int>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char const &,int *)" (??$ParseNaturalNumber@H@internal@testing@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAH@Z)'
LINK : warning LNK4217: symbol '_getenv' defined in 'libucrt.lib(getenv.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"bool __cdecl testing::internal::BoolFromGTestEnv(char const *,bool)" (?BoolFromGTestEnv@internal@testing@@YA_NPBD_N@Z)'
LINK : warning LNK4217: symbol '___acrt_iob_func' defined in 'libucrt.lib(_file.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"public: __thiscall testing::internal::GTestLog::~GTestLog(void)" (??1GTestLog@internal@testing@@QAE@XZ)'
LINK : warning LNK4217: symbol '__wcsicmp' defined in 'libucrt.lib(wcsicmp.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"public: static bool __cdecl testing::internal::String::CaseInsensitiveWideCStringEquals(wchar_t const *,wchar_t const *)" (?CaseInsensitiveWideCStringEquals@String@internal@testing@@SA_NPB_W0@Z)'
LINK : warning LNK4217: symbol '_fclose' defined in 'libucrt.lib(fclose.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char __cdecl testing::internal::GetCapturedStream(class testing::internal::CapturedStream * *)" (?GetCapturedStream@internal@testing@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAPAVCapturedStream@12@@Z)'
LINK : warning LNK4217: symbol '_fflush' defined in 'libucrt.lib(fflush.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"public: __thiscall testing::internal::GTestLog::~GTestLog(void)" (??1GTestLog@internal@testing@@QAE@XZ)'
LINK : warning LNK4217: symbol '__fileno' defined in 'libucrt.lib(fileno.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"void __cdecl testing::internal::ColoredPrintf(enum testing::internal::GTestColor,char const *,...)" (?ColoredPrintf@internal@testing@@YAXW4GTestColor@12@PBDZZ)'
LINK : warning LNK4217: symbol '_fputc' defined in 'libucrt.lib(fputc.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"void __cdecl testing::internal::DeathTestAbort(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char const &)" (?DeathTestAbort@internal@testing@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)'
LINK : warning LNK4217: symbol '___stdio_common_vfprintf' defined in 'libucrt.lib(output.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"void __cdecl testing::internal::ColoredPrintf(enum testing::internal::GTestColor,char const *,...)" (?ColoredPrintf@internal@testing@@YAXW4GTestColor@12@PBDZZ)'
LINK : warning LNK4217: symbol '___stdio_common_vsnprintf_s' defined in 'libucrt.lib(output.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '__snprintf_s'
LINK : warning LNK4217: symbol '_strncmp' defined in 'libucrt.lib(strncmp.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"char const * __cdecl testing::internal::ParseFlagValue(char const *,char const *,bool)" (?ParseFlagValue@internal@testing@@YAPBDPBD0_N@Z)'
LINK : warning LNK4217: symbol '_isdigit' defined in 'libucrt.lib(_ctype.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"bool __cdecl testing::internal::ParseNaturalNumber<int>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char const &,int *)" (??$ParseNaturalNumber@H@internal@testing@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAH@Z)'
LINK : warning LNK4217: symbol '_isxdigit' defined in 'libucrt.lib(_ctype.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"enum testing::internal::CharFormat __cdecl testing::internal::PrintCharsAsStringTo<char>(char const *,unsigned int,class std::basic_ostream<char,struct std::char_traits<char *)" (??$PrintCharsAsStringTo@D@internal@testing@@YA?AW4CharFormat@01@PBDIPAV?$basic_ostream@DU?$char_traits@D@std@@@std@@@Z)'
LINK : warning LNK4217: symbol '_isspace' defined in 'libucrt.lib(_ctype.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"class testing::AssertionResult __cdecl testing::internal::`anonymous namespace'::HRESULTFailureHelper(char const *,char const *,long)" (?HRESULTFailureHelper@?A0x0fcd2788@internal@testing@@YA?AVAssertionResult@3@PBD0J@Z)'
LINK : warning LNK4217: symbol '_iscntrl' defined in 'libucrt.lib(_ctype.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"bool __cdecl testing::internal::`anonymous namespace'::ContainsUnprintableControlCodes(char const *,unsigned int)" (?ContainsUnprintableControlCodes@?A0x0fcd2788@internal@testing@@YA_NPBDI@Z)'
LINK : warning LNK4217: symbol '_toupper' defined in 'libucrt.lib(tolower_toupper.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char __cdecl testing::internal::FlagToEnvVar(char const *)" (?FlagToEnvVar@internal@testing@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PBD@Z)'
LINK : warning LNK4217: symbol '__isatty' defined in 'libucrt.lib(isatty.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"void __cdecl testing::internal::ColoredPrintf(enum testing::internal::GTestColor,char const *,...)" (?ColoredPrintf@internal@testing@@YAXW4GTestColor@12@PBDZZ)'
LINK : warning LNK4217: symbol '__open_osfhandle' defined in 'libucrt.lib(osfinfo.obj)' is imported by 'gtest.lib(gtest-all.obj)' in function '"public: virtual enum testing::internal::DeathTest::TestRole __thiscall testing::internal::WindowsDeathTest::AssumeRole(void)" (?AssumeRole@WindowsDeathTest@internal@testing@@UAE?AW4TestRole@DeathTest@23@XZ)'
LINK : warning LNK4286: symbol '__close' defined in 'libucrt.lib(close.obj)' is imported by 'OLDNAMES.lib(close.obi)'
LINK : warning LNK4286: symbol '__read' defined in 'libucrt.lib(read.obj)' is imported by 'OLDNAMES.lib(read.obi)'
LINK : warning LNK4286: symbol '__write' defined in 'libucrt.lib(write.obj)' is imported by 'OLDNAMES.lib(write.obi)'
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp___stat64i32 referenced in function "public: bool __thiscall testing::internal::FilePath::DirectoryExists(void)const " (?DirectoryExists@FilePath@internal@testing@@QBE_NXZ)
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__fopen referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char __cdecl testing::internal::GetCapturedStream(class testing::internal::CapturedStream * *)" (?GetCapturedStream@internal@testing@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAPAVCapturedStream@12@@Z)
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__fread referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char __cdecl testing::internal::ReadEntireFile(struct _iobuf *)" (?ReadEntireFile@internal@testing@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAU_iobuf@@@Z)
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__fseek referenced in function "unsigned int __cdecl testing::internal::GetFileSize(struct _iobuf *)" (?GetFileSize@internal@testing@@YAIPAU_iobuf@@@Z)
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__ftell referenced in function "unsigned int __cdecl testing::internal::GetFileSize(struct _iobuf *)" (?GetFileSize@internal@testing@@YAIPAU_iobuf@@@Z)
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__fwrite referenced in function "public: int __thiscall testing::UnitTest::Run(void)" (?Run@UnitTest@testing@@QAEHXZ)
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__remove referenced in function "public: __thiscall testing::internal::ScopedPrematureExitFile::~ScopedPrematureExitFile(void)" (??1ScopedPrematureExitFile@internal@testing@@QAE@XZ)
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__fdopen referenced in function "struct _iobuf * __cdecl testing::internal::posix::FDOpen(int,char const *)" (?FDOpen@posix@internal@testing@@YAPAU_iobuf@@HPBD@Z)
OLDNAMES.lib(fdopen.obi) : error LNK2001: unresolved external symbol __imp__fdopen
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp___strdup referenced in function "private: void __thiscall testing::internal::RE::Init(char const *)" (?Init@RE@internal@testing@@AAEXPBD@Z)
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__strerror referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char __cdecl testing::internal::GetLastErrnoDescription(void)" (?GetLastErrnoDescription@internal@testing@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp___stricmp referenced in function "public: static bool __cdecl testing::internal::String::CaseInsensitiveCStringEquals(char const *,char const *)" (?CaseInsensitiveCStringEquals@String@internal@testing@@SA_NPBD0@Z)
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp___getcwd referenced in function "public: static class testing::internal::FilePath __cdecl testing::internal::FilePath::GetCurrentDir(void)" (?GetCurrentDir@FilePath@internal@testing@@SA?AV123@XZ)
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp___mkdir referenced in function "public: bool __thiscall testing::internal::FilePath::CreateFolder(void)const " (?CreateFolder@FilePath@internal@testing@@QBE_NXZ)
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__close referenced in function "void __cdecl testing::internal::CaptureStream(int,char const *,class testing::internal::CapturedStream * *)" (?CaptureStream@internal@testing@@YAXHPBDPAPAVCapturedStream@12@@Z)
OLDNAMES.lib(close.obi) : error LNK2001: unresolved external symbol __imp__close
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__creat referenced in function "void __cdecl testing::internal::CaptureStream(int,char const *,class testing::internal::CapturedStream * *)" (?CaptureStream@internal@testing@@YAXHPBDPAPAVCapturedStream@12@@Z)
OLDNAMES.lib(creat.obi) : error LNK2001: unresolved external symbol __imp__creat
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__dup referenced in function "void __cdecl testing::internal::CaptureStream(int,char const *,class testing::internal::CapturedStream * *)" (?CaptureStream@internal@testing@@YAXHPBDPAPAVCapturedStream@12@@Z)
OLDNAMES.lib(dup.obi) : error LNK2001: unresolved external symbol __imp__dup
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__dup2 referenced in function "void __cdecl testing::internal::CaptureStream(int,char const *,class testing::internal::CapturedStream * *)" (?CaptureStream@internal@testing@@YAXHPBDPAPAVCapturedStream@12@@Z)
OLDNAMES.lib(dup2.obi) : error LNK2001: unresolved external symbol __imp__dup2
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__read referenced in function "void __cdecl testing::internal::FailFromInternalError(int)" (?FailFromInternalError@internal@testing@@YAXH@Z)
OLDNAMES.lib(read.obi) : error LNK2001: unresolved external symbol __imp__read
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp__write referenced in function "protected: virtual void __thiscall testing::internal::DeathTestImpl::Abort(enum testing::internal::DeathTest::AbortReason)" (?Abort@DeathTestImpl@internal@testing@@MAEXW4AbortReason@DeathTest@23@@Z)
OLDNAMES.lib(write.obi) : error LNK2001: unresolved external symbol __imp__write
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp___localtime64_s referenced in function "bool __cdecl testing::internal::PortableLocaltime(__int64,struct tm *)" (?PortableLocaltime@internal@testing@@YA_N_JPAUtm@@@Z)
gtest.lib(gtest-all.obj) : error LNK2019: unresolved external symbol __imp___ftime64 referenced in function "__int64 __cdecl testing::internal::GetTimeInMillis(void)" (?GetTimeInMillis@internal@testing@@YA_JXZ)
OLDNAMES.lib(fdopen.obi) : error LNK2001: unresolved external symbol __imp___fdopen
OLDNAMES.lib(creat.obi) : error LNK2001: unresolved external symbol __imp___creat
OLDNAMES.lib(dup.obi) : error LNK2001: unresolved external symbol __imp___dup
OLDNAMES.lib(dup2.obi) : error LNK2001: unresolved external symbol __imp___dup2
MSVCRT.lib(chandler4gs.obj) : error LNK2019: unresolved external symbol __except_handler4_common referenced in function __except_handler4
test.exe : fatal error LNK1120: 26 unresolved externals
Upvotes: 1
Views: 1226
Reputation: 121609
As you probably know, dup(), dup2(), creat() and friends are all "standard" C library functions ("standard" as "commonly available") ... that Visual Studio treats "differently".
SUGGESTION: try static linking, e.g. /MT
:
https://stackoverflow.com/a/56698430/421195
Change your Runtime library settings as below
Project properties --> C/C++ --> Code generation --> Runtime Library --> Multi-threaded Debug (/MTd) instead of /MDd
See also: Unable to compile VIX Programs
Upvotes: 0