Skip to content

Cannot compile with GCC, cannot run G++ compiled binary #537

@just-ero

Description

@just-ero

I'm a bit of a noob, so I'm sure I'm missing something.
This is my code:

#include <iostream>
int main() {
  std::cout << "Hello, world!";
  return 0;
}

This is the output of gcc main.cpp -o app -v:

Click to view
clang version 21.1.8 (https://github.com/llvm/llvm-project.git 2078da43e25a4623cab2d0d60decddf709aaea28)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/bin
Configuration file: C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/bin/x86_64-w64-windows-gnu.cfg
 "C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/bin/clang-21.exe" -cc1 -triple x86_64-w64-windows-gnu -emit-obj -dumpdir app- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -mms-bitfields -funwind-tables=2 -fno-sized-deallocation -fno-use-init-array -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=C:/Users/ero/Desktop/CppGccWin -v -fcoverage-compilation-dir=C:/Users/ero/Desktop/CppGccWin -resource-dir C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/lib/clang/21 -internal-isystem C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/x86_64-w64-mingw32/include/c++/v1 -internal-isystem C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/include/c++/v1 -internal-isystem C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/lib/clang/21/include -internal-isystem C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/x86_64-w64-mingw32/include -internal-isystem C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/x86_64-w64-mingw32/usr/include -internal-isystem C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/include -fdeprecated-macro -ferror-limit 19 -fmessage-length=199 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -exception-model=seh -fcolor-diagnostics -faddrsig -o C:/Users/ero/AppData/Local/Temp/main-a919e1.o -x c++ main.cpp
clang -cc1 version 21.1.8 based upon LLVM 21.1.8 default target x86_64-w64-mingw32
ignoring nonexistent directory "C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/x86_64-w64-mingw32/include/c++/v1"
ignoring nonexistent directory "C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/x86_64-w64-mingw32/include"
ignoring nonexistent directory "C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/x86_64-w64-mingw32/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/include/c++/v1
 C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/lib/clang/21/include
 C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/include
End of search list.
 "C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/bin/ld.lld" -m i386pep -Bdynamic -o app.exe C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/x86_64-w64-mingw32/lib/crt2.o C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/x86_64-w64-mingw32/lib/crtbegin.o -LC:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/x86_64-w64-mingw32/lib -LC:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/x86_64-w64-mingw32/mingw/lib -LC:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/lib -LC:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/lib/clang/21/lib/windows C:/Users/ero/AppData/Local/Temp/main-a919e1.o -lmingw32 C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/lib/clang/21/lib/windows/libclang_rt.builtins-x86_64.a -lunwind -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/lib/clang/21/lib/windows/libclang_rt.builtins-x86_64.a -lunwind -lmoldname -lmingwex -lmsvcrt -lkernel32 C:/Users/ero/AppData/Local/Microsoft/WinGet/Packages/MartinStorsjo.LLVM-MinGW.MSVCRT_Microsoft.Winget.Source_8wekyb3d8bbwe/llvm-mingw-20251216-msvcrt-x86_64/x86_64-w64-mingw32/lib/crtend.o
ld.lld: error: undefined symbol: __cxa_begin_catch
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence[abi:ne210108]<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long long))
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::basic_ostream<char, std::__1::char_traits<char>>::sentry::~sentry())
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(__clang_call_terminate)

ld.lld: error: undefined symbol: std::__1::ios_base::__set_badbit_and_consider_rethrow()
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence[abi:ne210108]<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long long))

ld.lld: error: undefined symbol: __cxa_end_catch
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence[abi:ne210108]<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long long))
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence[abi:ne210108]<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long long))
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::basic_ostream<char, std::__1::char_traits<char>>::sentry::~sentry())

ld.lld: error: undefined symbol: __gxx_personality_seh0
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(.xdata$_ZNSt3__124__put_character_sequenceB8ne210108IcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_y)
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(.xdata$_ZNSt3__116__pad_and_outputB8ne210108IcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_)  
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(.xdata$_ZNSt3__119ostreambuf_iteratorIcNS_11char_traitsIcEEEC2B8ne210108ERNS_13basic_ostreamIcS2_EE)
>>> referenced 7 more times

ld.lld: error: undefined symbol: std::__1::basic_ostream<char, std::__1::char_traits<char>>::flush()
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::basic_ostream<char, std::__1::char_traits<char>>::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char>>&))

ld.lld: error: undefined symbol: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::~basic_string()
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>> std::__1::__pad_and_output[abi:ne210108]<char, std::__1::char_traits<char>>(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, char const*, char const*, char const*, std::__1::ios_base&, char))
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>> std::__1::__pad_and_output[abi:ne210108]<char, std::__1::char_traits<char>>(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, char const*, char const*, char const*, std::__1::ios_base&, char))

ld.lld: error: undefined symbol: std::uncaught_exceptions()
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::basic_ostream<char, std::__1::char_traits<char>>::sentry::~sentry())

ld.lld: error: undefined symbol: std::terminate()
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(__clang_call_terminate)

ld.lld: error: undefined symbol: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::__init(unsigned long long, char)
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string[abi:ne210108](unsigned long long, char))

ld.lld: error: undefined symbol: std::__1::ios_base::getloc() const
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::basic_ios<char, std::__1::char_traits<char>>::widen[abi:ne210108](char) const)

ld.lld: error: undefined symbol: std::__1::locale::~locale()
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::basic_ios<char, std::__1::char_traits<char>>::widen[abi:ne210108](char) const)
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::basic_ios<char, std::__1::char_traits<char>>::widen[abi:ne210108](char) const)

ld.lld: error: undefined symbol: std::__1::locale::use_facet(std::__1::locale::id&) const
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::ctype<char> const& std::__1::use_facet[abi:ne210108]<std::__1::ctype<char>>(std::__1::locale const&))

ld.lld: error: undefined symbol: std::__1::ios_base::clear(unsigned int)
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(std::__1::ios_base::setstate[abi:ne210108](unsigned int))

ld.lld: error: undefined symbol: std::__1::cout
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(.refptr._ZNSt3__14coutE)

ld.lld: error: undefined symbol: std::__1::ctype<char>::id
>>> referenced by C:/Users/ero/AppData/Local/Temp/main-a919e1.o:(.refptr._ZNSt3__15ctypeIcE2idE)
clang-21: error: linker command failed with exit code 1 (use -v to see invocation)

Compiling with g++ main.cpp -o app works, but the resulting binary cannot be executed:

The application was unable to start correctly (0xc000000e).

What's wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions