Skip to content

Linker errors on "Hello, world!" in Windows #11777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
llvmbot opened this issue Nov 19, 2011 · 11 comments
Closed

Linker errors on "Hello, world!" in Windows #11777

llvmbot opened this issue Nov 19, 2011 · 11 comments
Labels
bugzilla Issues migrated from bugzilla c++

Comments

@llvmbot
Copy link
Member

llvmbot commented Nov 19, 2011

Bugzilla Link 11405
Resolution FIXED
Resolved on Aug 02, 2013 18:52
Version unspecified
OS other
Blocks llvm/llvm-bugzilla-archive#12477
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@tritao,@rnk,@timurrrr

Extended Description

After downloading the current source, and building the compiler etc. using Visual C++ 10.0, it errs out on "Hello, world!" with various linker errors.

Providing some options that reportedly could help, the compiler crashed (ICE, it
called abort()).

See also my posting <url: http://stackoverflow.com/questions/8194375/clang-hello-world-link-errors-in-windows>

d:\dev\test> type con >foo.cpp #include using namespace std; int main() { cout << "Hello, cling-clong world!" << endl; } ^Z

d:\dev\test> clang++ foo.cpp
foo-839435.o : error LNK2019: unresolved external symbol __ZSt4cout referenced in function _main
foo-839435.o : error LNK2019: unresolved external symbol __ZdlPv referenced in function __ZNSt14error_categoryD0Ev
foo-839435.o : error LNK2019: unresolved external symbol __ZSt18uncaught_exceptionv referenced in function __ZNSo6sentry
D2Ev
foo-839435.o : error LNK2019: unresolved external symbol ___cxa_rethrow referenced in function __ZNSt8ios_base5clearEib
foo-839435.o : error LNK2019: unresolved external symbol ___cxa_allocate_exception referenced in function __ZNSt8ios_base5clearEib
foo-839435.o : error LNK2019: unresolved external symbol ___cxa_throw referenced in function __ZNSt8ios_base5clearEib
foo-839435.o : error LNK2019: unresolved external symbol __ZSt17iostream_categoryv referenced in function __ZSt15make_er

@llvmbot
Copy link
Member Author

llvmbot commented Nov 19, 2011

d:\dev\test> clang++ foo.cpp -Xclang -cxx-abi -Xclang microsoft Can't yet mangle constructors! UNREACHABLE executed at D:\dev\tools\llvm\tools\clang\lib\AST\MicrosoftMangle.cpp:1172! clang++: error: clang frontend command failed with exit code 3 (use -v to see invocation)

d:\dev\test> _
</ice example>

@llvmbot
Copy link
Member Author

llvmbot commented Nov 19, 2011

OS: Windows 7
CLang version: 3.1

@DougGregor
Copy link
Contributor

You'll need some kind of C++ standard library (e.g., the mingw libstdc++) to make this work. The Microsoft ABI is not yet implemented.

Not a release blocker.

@tritao
Copy link
Mannequin

tritao mannequin commented Jun 16, 2012

C:\LLVM\build\bin\Debug>clang -fno-rtti -Xclang -cxx-abi -Xclang microsoft hello1.cpp
In file included from hello1.cpp:1:
C:\VS10\VC\INCLUDE\xstring:700:15: error: cannot mangle this r-value reference type yet
basic_string(_Myt&& _Right)
^~~~~~
C:\VS10\VC\INCLUDE\xstring:700:15: error: cannot mangle this r-value reference type yet
basic_string(_Myt&& _Right)
^~~~~~
2 errors generated.

Tested with trunk, fails on r-value reference mangling in MS ABI.

@tritao
Copy link
Mannequin

tritao mannequin commented Jun 18, 2012

*** Bug llvm/llvm-bugzilla-archive#12336 has been marked as a duplicate of this bug. ***

@tritao
Copy link
Mannequin

tritao mannequin commented Jun 21, 2012

As of r158895 and with the nullptr_t stddef.h patch in the mailing list, this reaches code generation, though it crashes in there.

C:\LLVM\build\bin\Debug>clang++ -fno-rtti -Xclang -cxx-abi -Xclang microsoft -c 11405.cpp
Assertion failed: Idx < getNumArgs() && "Argument index out of range!", file C:\LLVM\tools\clang\include\clang/Basic/Diagnostic.h, line 1005
Stack dump:
0. Program arguments: C:/Users/Tritonite/Development/Flush/dep/LLVM/build/bin/Debug/clang++.exe -cc1 -triple i686-pc-win32 -emit-obj -mrelax-all -disable-free -main-file-name 11405.cpp -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -momit-leaf-frame-pointer -coverage-file 11405.o -resource-dir C:/Users/Tritonite/Development/Flush/dep/LLVM/build/bin/Debug..\lib\clang\3.2 -fmodule-cache-path C:\Users\TRITON~1\AppData\Local\Temp\clang-module-cache -internal-isystem C:/Users/Tritonite/Development/Flush/dep/LLVM/build/bin/Debug/../lib/clang/3.2/include -internal-isystem C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE -internal-isystem C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\INCLUDE -internal-isystem C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include -fdeprecated-macro -ferror-limit 19 -fmessage-length 210 -mstackrealign -fno-rtti -fms-extensions -fms-compatibility -fmsc-version=1300 -fdelayed-template-parsing -fobjc-runtime=gnu-fragile -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -cxx-abi microsoft -o 11405.o -x c++ 11405.cpp

  1.  <eof> parser at end of file
    
  2.  Per-file LLVM IR generation
    
  3.  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\ostream:764:32: Generating code for declaration 'std::operator<<'
    
  4.  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\ostream:767:2: LLVM IR generation of compound statement ('{}')
    

Stack:
_get_pgmptr() + 0x21B bytes(s)
abort() + 0x1E bytes(s)
_wassert() + 0xD6 bytes(s)
clang::Diagnostic::getArgKind() + 0x3C bytes(s), c:\llvm\tools\clang\include\clang\basic\diagnostic.h, line 1005 + 0x2D byte(s)
clang::Diagnostic::FormatDiagnostic() + 0x2C9 bytes(s), c:\llvm\tools\clang\lib\basic\diagnostic.cpp, line 717 + 0xF byte(s)
clang::Diagnostic::FormatDiagnostic() + 0x99 bytes(s), c:\llvm\tools\clang\lib\basic\diagnostic.cpp, line 651
clang::TextDiagnosticPrinter::HandleDiagnostic() + 0x56 bytes(s), c:\llvm\tools\clang\lib\frontend\textdiagnosticprinter.cpp, line 128
clang::DiagnosticIDs::ProcessDiag() + 0x294 bytes(s), c:\llvm\tools\clang\lib\basic\diagnosticids.cpp, line 667 + 0x1F byte(s)
clang::DiagnosticsEngine::ProcessDiag() + 0x24 bytes(s), c:\llvm\tools\clang\include\clang\basic\diagnostic.h, line 703
clang::DiagnosticsEngine::EmitCurrentDiagnostic() + 0x26 bytes(s), c:\llvm\tools\clang\lib\basic\diagnostic.cpp, line 386 + 0x8 byte(s)
clang::DiagnosticBuilder::Emit() + 0x3C bytes(s), c:\llvm\tools\clang\include\clang\basic\diagnostic.h, line 830 + 0xA byte(s)
clang::DiagnosticBuilder::~DiagnosticBuilder() + 0x16 bytes(s), c:\llvm\tools\clang\include\clang\basic\diagnostic.h, line 858
ErrorUnsupportedABI() + 0x97 bytes(s), c:\llvm\tools\clang\lib\codegen\cgcxxabi.cpp, line 30
clang::CodeGen::CGCXXABI::EmitMemberPointerIsNotNull() + 0x2F bytes(s), c:\llvm\tools\clang\lib\codegen\cgcxxabi.cpp, line 92 + 0x18 byte(s)
anonymous namespace'::ScalarExprEmitter::VisitCastExpr() + 0xA6C bytes(s), c:\llvm\tools\clang\lib\codegen\cgexprscalar.cpp, line 1217 + 0x39 byte(s) clang::StmtVisitorBase<clang::make_ptr,anonymous namespace'::ScalarExprEmitter,llvm::Value *>::VisitImplicitCastExpr() + 0x1A bytes(s), c:\llvm\build\tools\clang\include\clang\ast\stmtnodes.inc, line 353 + 0x1A byte(s)
clang::StmtVisitorBase<clang::make_ptr,anonymous namespace'::ScalarExprEmitter,llvm::Value *>::Visit() + 0x740 bytes(s), c:\llvm\tools\clang\include\clang\ast\stmtvisitor.h, line 353 + 0xC byte(s) anonymous namespace'::ScalarExprEmitter::Visit() + 0x1A bytes(s), c:\llvm\tools\clang\lib\codegen\cgexprscalar.cpp, line 152
clang::CodeGen::CodeGenFunction::EmitScalarExpr() + 0xA9 bytes(s), c:\llvm\tools\clang\lib\codegen\cgexprscalar.cpp, line 2749 + 0x1C byte(s)
clang::CodeGen::CodeGenFunction::EvaluateExprAsBool() + 0xE5 bytes(s), c:\llvm\tools\clang\lib\codegen\cgexpr.cpp, line 92 + 0x21 byte(s)
clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr() + 0x3C5 bytes(s), c:\llvm\tools\clang\lib\codegen\codegenfunction.cpp, line 676 + 0xC byte(s)
clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr() + 0x2BA bytes(s), c:\llvm\tools\clang\lib\codegen\codegenfunction.cpp, line 651 + 0x19 byte(s)
clang::CodeGen::CodeGenFunction::EmitIfStmt() + 0x161 bytes(s), c:\llvm\tools\clang\lib\codegen\cgstmt.cpp, line 414
clang::CodeGen::CodeGenFunction::EmitStmt() + 0x208 bytes(s), c:\llvm\tools\clang\lib\codegen\cgstmt.cpp, line 127 + 0x15 byte(s)
clang::CodeGen::CodeGenFunction::EmitCompoundStmt() + 0xAC bytes(s), c:\llvm\tools\clang\lib\codegen\cgstmt.cpp, line 203 + 0xE byte(s)
clang::CodeGen::CodeGenFunction::EmitSimpleStmt() + 0x93 bytes(s), c:\llvm\tools\clang\lib\codegen\cgstmt.cpp, line 175 + 0x39 byte(s)
clang::CodeGen::CodeGenFunction::EmitStmt() + 0x54 bytes(s), c:\llvm\tools\clang\lib\codegen\cgstmt.cpp, line 47 + 0xC byte(s)
clang::CodeGen::CodeGenFunction::EmitFunctionBody() + 0x96 bytes(s), c:\llvm\tools\clang\lib\codegen\codegenfunction.cpp, line 400
clang::CodeGen::CodeGenFunction::GenerateCode() + 0x315 bytes(s), c:\llvm\tools\clang\lib\codegen\codegenfunction.cpp, line 470
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition() + 0x27C bytes(s), c:\llvm\tools\clang\lib\codegen\codegenmodule.cpp, line 1836 + 0x2A byte(s)
clang::CodeGen::CodeGenModule::EmitGlobalDefinition() + 0x14F bytes(s), c:\llvm\tools\clang\lib\codegen\codegenmodule.cpp, line 988 + 0xC byte(s)
clang::CodeGen::CodeGenModule::EmitDeferred() + 0x151 bytes(s), c:\llvm\tools\clang\lib\codegen\codegenmodule.cpp, line 700
clang::CodeGen::CodeGenModule::Release() + 0x20 bytes(s), c:\llvm\tools\clang\lib\codegen\codegenmodule.cpp, line165
`anonymous namespace'::CodeGeneratorImpl::HandleTranslationUnit() + 0x5C bytes(s), c:\llvm\tools\clang\lib\codegen\modulebuilder.cpp, line 102
clang::BackendConsumer::HandleTranslationUnit() + 0x6A bytes(s), c:\llvm\tools\clang\lib\codegen\codegenaction.cpp, line 117 + 0x21 byte(s)
clang::ParseAST() + 0x240 bytes(s), c:\llvm\tools\clang\lib\parse\parseast.cpp, line 110 + 0x18 byte(s)
clang::ASTFrontendAction::ExecuteAction() + 0xED bytes(s), c:\llvm\tools\clang\lib\frontend\frontendaction.cpp, line 418 + 0x30 byte(s)
clang::CodeGenAction::ExecuteAction() + 0x341 bytes(s), c:\llvm\tools\clang\lib\codegen\codegenaction.cpp, line 422
clang::FrontendAction::Execute() + 0xC3 bytes(s), c:\llvm\tools\clang\lib\frontend\frontendaction.cpp, line 335 +0xF byte(s)
clang::CompilerInstance::ExecuteAction() + 0x281 bytes(s), c:\llvm\tools\clang\lib\frontend\compilerinstance.cpp, line 678
clang::ExecuteCompilerInvocation() + 0x2C8 bytes(s), c:\llvm\tools\clang\lib\frontendtool\executecompilerinvocation.cpp, line 188 + 0x11 byte(s)
cc1_main() + 0x3C9 bytes(s), c:\llvm\tools\clang\tools\driver\cc1_main.cpp, line 165 + 0xE byte(s)
main() + 0x149 bytes(s), c:\llvm\tools\clang\tools\driver\driver.cpp, line 358 + 0x45 byte(s)
__tmainCRTStartup() + 0x1BF bytes(s), f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c, line 555 + 0x19 byte(s)
mainCRTStartup() + 0xF bytes(s), f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c, line 371
BaseThreadInitThunk() + 0xE bytes(s)
LdrInitializeThunk() + 0x12C bytes(s)
LdrInitializeThunk() + 0xFF bytes(s)

@tritao
Copy link
Mannequin

tritao mannequin commented Jun 23, 2012

By the way, this also fails in non-MS ABI because it tries to link with the MS C standard library while generating Itanium mangled names.

We should just error out in that case, since with the MS library headers it will never work.

@llvmbot
Copy link
Member Author

llvmbot commented Jun 12, 2013

Following the steps described at http://llvm.org/docs/GettingStartedVS.html fails in step 6 with two unresolved externals:

C:\Program Files (x86)\Microsoft Visual Studio 11.0>link -defaultlib:libcmt -out
:"f:\projects\sandbox\llvm-tests\bin\hello_world.exe" "F:\Projects\Sandbox\llvm-
tests\bin\hello_world.obj
Microsoft (R) Incremental Linker Version 11.00.60315.1
Copyright (C) Microsoft Corporation. All rights reserved.

hello_world.obj : error LNK2019: unresolved external symbol printf referenced in
function main
LINK : error LNK2001: unresolved external symbol mainCRTStartup
f:\projects\sandbox\llvm-tests\bin\hello_world.exe : fatal error LNK1120: 2 unre
solved externals

@rnk
Copy link
Collaborator

rnk commented Aug 3, 2013

There seem to be a few issues here:

  1. hello world with iostream with MSVCRT
  2. hello world with printf with MSVCRT
  3. hello world with some other standard libraries

Today there are no more link errors with iostream hello world and the MSVCRT. There are errors about intrin.h which are outstanding, but if I hack around it locally I can get the following to work:

$ ls intrin.h
intrin.h

$ cat hello.cpp
#include
int main() {
std::cout << "hello, world!" << std::endl;
}

$ clang -fmsc-version=1700 -isystem . -msse4a -D_HAS_EXCEPTIONS=0 -fno-rtti -fno-exceptions -Xclang -cxx-abi -Xclang microsoft hello.cpp && ./a.out
hello, world!

We already have issues open about supporting Microsoft intrinsics and resolving these issues, so I don't see a need to keep this open:
http://llvm.org/bugs/show_bug.cgi?id=13283

@tritao
Copy link
Mannequin

tritao mannequin commented Nov 26, 2021

mentioned in issue llvm/llvm-bugzilla-archive#12336

@timurrrr
Copy link
Contributor

mentioned in issue llvm/llvm-bugzilla-archive#12477

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++
Projects
None yet
Development

No branches or pull requests

4 participants