[LLVMdev] Beginner Question on Linking

Nathan Zaugg nzaugg at gmail.com
Thu Sep 29 08:46:08 PDT 2011


I am following along in http://llvm.org/docs/GettingStartedVS.html with a
Hello World bitcode file. I can run the file using the command `lli
HelloWorld.bc`, but now I want to link it into an executable file (on
windows). The next thing the document says to run is `llc -filetype=obj
HelloWorld.bc` which runs fine and now I have a `HelloWorld.obj` file. It's
the last step that is giving me some trouble. The command `link hello.obj
-defaultlib:libcmt` in MinGW yields the following error: `link: invalid
option --d Try `link --help` for more information`. I drop the
`-defaultlib:libcmt` and the linker creates an executable but when I try to
run it I get the following errors:

Popup:
---------------------------
Unsupported 16-Bit Application
---------------------------
The program or feature
"\??\D:\OpenSource\LLVM\mybuilddir\bin\Debug\HelloWorld.exe" cannot start or
run due to incompatibity with 64-bit versions of Windows. Please contact the
software vendor to ask if a 64-bit Windows compatible version is available.


---------------------------
OK
---------------------------

Console:
`This version of D:\OpenSource\LLVM\mybuilddir\bin\Debug\HelloWorld.exe is
not compatible with the version of Windows you're running. Check your
computer's system information to see whether you need an x86 (32-bit) or x64
(64-bit) version of the program, and then contact the software publisher.`


I try to use `llvm-link HelloWorld.bc -defaultlib:libcmt` and I get
`llvm-link: Unknown command line argument '-defaultlib:libcmt'. Try:
'llvm-link -help' llvm-link: Did you mean '-debug-only'?` I drop the
`-defaultlib:libcmt`
and change the command to `llvm-link HelloWorld.bc HelloWorld.exe` and get
these errors:

Popup:
--------------------------- Microsoft Visual C++ Debug Library
--------------------------- Debug Assertion Failed! Program:
D:\OpenSource\LLVM\mybuilddir\bin\Debug\llvm-link.exe File:
f:\dd\vctools\crt_bld\self_64_amd64\crt\src\isctype.c Line: 56 Expression:
(unsigned)(c + 1) <= 256 For information on how your program can cause an
assertion failure, see the Visual C++ documentation on asserts. (Press Retry
to debug the application) --------------------------- Abort Retry Ignore
---------------------------

After Clicking "Ignore", I get the message agan. Ignore again and I get:
`llvm-link: HelloWorld.bf.obj:1:1: error: expected top-level entity då☺
4îäN♀☻ .text 0☺ < l☺ ► P`VWHâ∞(╣ ☺ Φ Hë╞Hë±1 ╥A╕ ☺ Φ Çå Ç ^ llvm-link: error
loading file 'HelloWorld.bf.obj'`

Yes, that's binary data output in the console. I was successful outputting
x86 assembly and then assembling the emitted assembly, but I wanted to more
directly compile the code. Also, gcc doesn't like the x64 assembler so it
has to be forced to x86 before that will work.

Any ideas?

Thanks!
Nate
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110929/98bf0513/attachment.html>


More information about the llvm-dev mailing list