Побег из визуальной студииC++

Программы на C++. Форум разработчиков
Anonymous
 Побег из визуальной студии

Сообщение Anonymous »

Я всегда использовал C++ в Visual Studio,
но я сталкивался с плохими, почти бесполезными или вводящими в заблуждение сообщениями об ошибках в MSVC, а усложнение моей базы кода приводило к сбою MSVC.
Итак, я начал использовать clang-cl с Visual Studio.
Однако он по-прежнему ограничен, как и в модулях, поэтому я действительно хочу перенести в него свой код.
Я знаю о makefile и cmake, но я хотел начать как можно проще, чтобы понять, как работает магия.
Поэтому я начал с clang++ на терминале PowerShell для разработки Visual Studio.

Код: Выделить всё

#include 
int main()
{
std::cout >> referenced by Test.o:(.xdata)
>>> referenced by Test.o:(.xdata)
>>> referenced by Test.o:(.xdata)
>>> referenced 14 more times

lld-link: error: undefined symbol: strlen
>>> referenced by Test.o:(public: static unsigned __int64 __cdecl std::_Narrow_char_traits::length(char const *const))

lld-link: error: undefined symbol: __std_terminate
>>> referenced by Test.o:(int `public: __cdecl std::basic_ostream::_Sentry_base::~_Sentry_base(void)'::`1'::dtor$4)
>>> referenced by Test.o:(int `public: __cdecl std::exception::exception(class exception::dtor$2 const &)'::`1'::dtor$2)
>>> referenced by Test.o:(int `public: virtual __cdecl std::exception::~exception(void)'::`1'::dtor$2)
>>> referenced 18 more times

lld-link: error: undefined symbol: _CxxThrowException
>>> referenced by Test.o:(public: void __cdecl std::ios_base::clear(int, bool))
>>>  referenced by Test.o:(public: void __cdecl std::ios_base::clear(int, bool))
>>> referenced by Test.o:(void __cdecl std::_Throw_bad_array_new_length(void))
>>> referenced 12 more times

lld-link: error: undefined symbol: __std_exception_copy
>>> referenced by Test.o:(public: __cdecl std::exception::exception(class std::exception const &))
>>> referenced by Test.o:(public: __cdecl std::exception::exception(char const *const))
>>> referenced by libcpmt.lib(xthrow.obj):($LN9)
>>> referenced 14 more times

lld-link: error: undefined symbol: _tls_index
>>> referenced by Test.o:(class std::_Iostream_error_category2 const & __cdecl std::_Immortalize_memcpy_image(void))

lld-link: error: undefined symbol: _Init_thread_epoch
>>> referenced by Test.o:(class std::_Iostream_error_category2 const & __cdecl std::_Immortalize_memcpy_image(void))

lld-link: error: undefined symbol: _Init_thread_header
>>> referenced by Test.o:(class std::_Iostream_error_category2 const & __cdecl std::_Immortalize_memcpy_image(void))

lld-link: error: undefined symbol: atexit
>>> referenced by Test.o:(class std::_Iostream_error_category2 const & __cdecl std::_Immortalize_memcpy_image(void))
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\src\cout.cpp:13
>>>               libcpmt.lib(cout.obj):(void __cdecl `dynamic initializer for 'initlocks''(void))
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\src\cout.cpp:17
>>>               libcpmt.lib(cout.obj):(void __cdecl `dynamic initializer for 'std::fout''(void))
>>> referenced 6 more times

lld-link: error: undefined symbol: _Init_thread_footer
>>> referenced by Test.o:(class std::_Iostream_error_category2 const & __cdecl std::_Immortalize_memcpy_image(void))

lld-link: error: undefined symbol: void __cdecl operator delete(void *, unsigned __int64)
>>> referenced by Test.o:(public: virtual void * __cdecl std::_Iostream_error_category2::`scalar deleting dtor'(unsigned int))
>>> referenced by Test.o:(public: virtual void * __cdecl std::bad_array_new_length::`scalar deleting dtor'(unsigned int))
>>> referenced by Test.o:(public: virtual void * __cdecl std::bad_alloc::`scalar deleting dtor'(unsigned int))
>>> referenced 178 more times

lld-link: error: undefined symbol: memset
>>> referenced by Test.o:(public: __cdecl std::_String_val::_Bxty::_Bxty(void))
>>> referenced by Test.o:(public: __cdecl std::exception::exception(char const *const, int))
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\inc\__msvc_string_view.hpp:159
>>>               libcpmt.lib(locale.obj):($LN13)
>>> referenced 11 more times

lld-link: error: undefined symbol: memcpy
>>> referenced by Test.o:(public: static char * __cdecl std::_Char_traits::copy(char *const, char const *const, unsigned __int64))
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\inc\xlocale:2852
>>>               libcpmt.lib(cout.obj):($LN4)
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\inc\xlocale:2863
>>>               libcpmt.lib(cout.obj):($LN4)
>>> referenced 107 more times

lld-link: error: undefined symbol: _invalid_parameter_noinfo_noreturn
>>> referenced by Test.o:(void * __cdecl std::_Allocate_manually_vector_aligned(unsigned __int64))
>>> referenced by Test.o:(void __cdecl std::_Adjust_manually_vector_aligned(void *&, unsigned __int64 &))
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\inc\xstring:3022
>>>               libcpmt.lib(cout.obj):($LN166)
>>> referenced 45 more times

lld-link: error: undefined symbol: void * __cdecl operator new(unsigned __int64)
>>> referenced by Test.o:(public: static void * __cdecl std::_Default_allocate_traits::_Allocate(unsigned __int64))
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\inc\xlocale:2782
>>>               libcpmt.lib(cout.obj):($LN41)
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\inc\xiosbase:388
>>>               libcpmt.lib(cout.obj):($LN12)
>>>  referenced 112 more times

lld-link: error: undefined symbol: __std_exception_destroy
>>> referenced by Test.o:(public: virtual __cdecl std::exception::~exception(void))
>>> referenced by libcpmt.lib(xthrow.obj):(public: virtual __cdecl std::bad_function_call::~bad_function_call(void))
>>> referenced by libcpmt.lib(xthrow.obj):($LN15)
>>> referenced 14 more times

lld-link: error: undefined symbol: memmove
>>> referenced by Test.o:(public: static char * __cdecl std::_Char_traits::move(char *const, char const *const, unsigned __int64))
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\inc\xstring:1869
>>>               libcpmt.lib(cout.obj):($LN83)
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\inc\xstring:1780
>>>               libcpmt.lib(locale.obj):($LN97)
>>> referenced 6 more times

lld-link: error: undefined symbol: const type_info::`vftable'
>>> referenced by Test.o:(class std::ios_base::failure `RTTI Type Descriptor')
>>> referenced by Test.o:(class std::system_error `RTTI Type Descriptor')
>>> referenced by Test.o:(class std::_System_error `RTTI Type Descriptor')
>>> referenced 71 more times

lld-link: error: undefined symbol: __declspec(dllimport) FormatMessageA
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\src\syserror.cpp:230
>>>               libcpmt.lib(syserror.obj):($LN4)
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\src\syserror_import_lib.cpp:49
>>>               libcpmt.lib(syserror_import_lib.obj):($LN21)

lld-link: error: undefined symbol: _purecall
>>> referenced by libcpmt.lib(cout.obj):(const std::_Facet_base::`vftable')
>>> referenced by libcpmt.lib(cout.obj):(const std::_Facet_base::`vftable')
>>> referenced by libcpmt.lib(locale0.obj)

lld-link: error: too many errors emitted, stopping now (use /errorlimit:0 to see all errors)
Я также пробовал удалить #include и cout

Код: Выделить всё

int main()
{
return 0;
};
и вызывал команды clang с помощью компоновщика MSVC или llvm;
они оба работали без ошибок.
Я пытался связать также библиотека x64 с компоновщиком MSVC.

Код: Выделить всё

 link Test.o /LIBPATH:"D:\Programs\Visual Studioes\Visual Studio 2022\001\VC\Tools\MSVC\14.41.34120\lib\x64" /OUT:Test.exe /ENTRY:main
и огромные ошибки меня потрясли.

Код: Выделить всё

Microsoft (R) Incremental Linker Version 14.41.34120.0
Copyright (C) Microsoft Corporation.   All rights reserved.

Test.o : error LNK2001: unresolved external symbol __CxxFrameHandler3
Test.o : error LNK2019: unresolved external symbol strlen referenced in function "public: static unsigned __int64 __cdecl std::_Narrow_char_traits::length(char const * const)" (?length@?$_Narrow_char_traits@DH@std@@SA_KQEBD@Z)
libcpmt.lib(wlocale.obj) : error LNK2001: unresolved external symbol __std_terminate
libcpmt.lib(xlocale.obj) : error LNK2001: unresolved external symbol __std_terminate
Test.o : error LNK2001: unresolved external symbol __std_terminate
libcpmt.lib(cout.obj) : error LNK2001: unresolved external symbol __std_terminate
libcpmt.lib(iosptrs.obj) : error LNK2001: unresolved external symbol __std_terminate
libcpmt.lib(locale.obj) : error LNK2001: unresolved external symbol __std_terminate
libcpmt.lib(wlocale.obj) : error LNK2001: unresolved external symbol _CxxThrowException
libcpmt.lib(xlocale.obj) : error LNK2001: unresolved external symbol _CxxThrowException
Test.o : error LNK2001: unresolved external symbol _CxxThrowException
libcpmt.lib(cout.obj) : error LNK2001: unresolved external symbol _CxxThrowException
libcpmt.lib(xthrow.obj) : error LNK2001: unresolved external symbol _CxxThrowException
libcpmt.lib(locale.obj) : error LNK2001: unresolved external symbol _CxxThrowException
libcpmt.lib(wlocale.obj) : error LNK2001: unresolved external symbol __std_exception_copy
libcpmt.lib(xlocale.obj) : error LNK2001: unresolved external symbol __std_exception_copy
Test.o : error LNK2001: unresolved external symbol __std_exception_copy
libcpmt.lib(cout.obj) : error LNK2001: unresolved external symbol __std_exception_copy
libcpmt.lib(xthrow.obj) : error LNK2001: unresolved external symbol __std_exception_copy
libcpmt.lib(locale.obj) : error LNK2001: unresolved external symbol __std_exception_copy
Test.o : error LNK2019: unresolved external symbol _tls_index referenced in function "class std::_Iostream_error_category2 const & __cdecl std::_Immortalize_memcpy_image(void)" (??$_Immortalize_memcpy_image@V_Iostream_error_category2@std@@@std@@YAAEBV_Iostream_error_category2@0@XZ)
Test.o : error LNK2019: unresolved external symbol _Init_thread_epoch referenced in function "class std::_Iostream_error_category2 const & __cdecl std::_Immortalize_memcpy_image(void)" (??$_Immortalize_memcpy_image@V_Iostream_error_category2@std@@@std@@YAAEBV_Iostream_error_category2@0@XZ)
Test.o : error LNK2019: unresolved external symbol _Init_thread_header referenced in function "class std::_Iostream_error_category2 const & __cdecl std::_Immortalize_memcpy_image(void)" (??$_Immortalize_memcpy_image@V_Iostream_error_category2@std@@@std@@YAAEBV_Iostream_error_category2@0@XZ)
libcpmt.lib(iosptrs.obj) : error LNK2001: unresolved external symbol atexit
Test.o : error LNK2001: unresolved external symbol atexit
libcpmt.lib(cout.obj) : error LNK2001: unresolved external symbol atexit
libcpmt.lib(xlock.obj) : error LNK2001: unresolved external symbol atexit
libcpmt.lib(locale0.obj) : error LNK2001: unresolved external symbol atexit
Test.o : error LNK2019: unresolved external symbol _Init_thread_footer referenced in function "class std::_Iostream_error_category2 const & __cdecl std::_Immortalize_memcpy_image(void)" (??$_Immortalize_memcpy_image@V_Iostream_error_category2@std@@@std@@YAAEBV_Iostream_error_category2@0@XZ)
libcpmt.lib(ios.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z)
libcpmt.lib(locale.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z)
libcpmt.lib(wlocale.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z)
libcpmt.lib(xlocale.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z)
Test.o : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z)
libcpmt.lib(cout.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z)
libcpmt.lib(xthrow.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z)
libcpmt.lib(locale0.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)"  (??3@YAXPEAX_K@Z)
Test.o : error LNK2019: unresolved external symbol memset referenced in function "public: __cdecl
Test.exe : fatal error LNK1120: 99 unresolved externals
И есть еще кое-что, но я удалил это из-за ограничения длины.
Я также пытался заставить clang производить компиляцию x86,
но это привело к аналогичному результату с огромным набором нераспознанных функций std.

Подробнее здесь: https://stackoverflow.com/questions/790 ... ual-studio

Вернуться в «C++»