[LLVMdev] A small doubt

Brian R. Gaeke gaeke at uiuc.edu
Mon Oct 27 22:14:01 PST 2003


> Hi LLVMDev,
> 
> The GCC frontend for LLVM inserts a call to a __main() in the
> main() function. Whats the purpose of this? And which LLVM
> library do I need to link to satisfy the reference?

__main is used primarily to call static constructors. The way you
satisfy this dependency is to link the bytecode file against crtend.o
(aka libcrtend.bc).  This is normally accomplished by using gccld
(or by llvm-gcc <bytecode files> -o program, which calls gccld).

If you're in a pinch, and you absolutely know for sure that you
won't ever have any static constructors called in your program, you
can replace __main with an empty function. But I heartily recommend
the solution above, because it's much more complete and only minimally
more painful.

Hope this helps,
-Brian

-- 
gaeke at uiuc.edu



More information about the llvm-dev mailing list