This project is read-only.

Cannot compile helloworld.cs example

Sep 25, 2015 at 3:56 AM
Edited Sep 25, 2015 at 4:00 AM
I am very interested in this project, but I have unfortunately failed to compile the helloworld.cs example :(

My environment:
  • CPU i7 x64, Win8.1 x64, .Net 4.5.1
  • LLVM in c:\Program Files (x86)\LLVM\ [installed from LLVM-3.7.0-win32.exe]
  • GCC in d:\TDM-GCC-32\ [ installed from tdm-gcc-5.1.0-3.exe]
  • IL2C in d:\IL2C\ [unzipped from il2c_10082015.7z]
  1. Created helloworld.cs in the D:\IL2C\ directory
  2. Generated the C files [helloworld.cpp and helloworld.h]
    Il2c.exe helloworld.cs /corelib:CoreLib.dll
  3. Generated corelib.cpp and corelib.h
    Il2c.exe CoreLib.dll
  4. Tried but failed to compile the .exe file
    g++ -o helloworld.exe helloworld.cpp CoreLib.cpp -lstdc++ -lgcmt-lib -march=i686 -L .
I've got his err:
helloworld.cpp:3345:7: warning: second argument of 'Int32 main(Int32, SByte**)' should be 'char ' [-Wmain]
Int32 main(Int32 count, SByte
parameters) {
CoreLib.cpp: In function 'Void Void_System_Array_InternalGetReferenceFVoidP__Int32__Int32PN(System_Array*, Void*, Int32, Int32*)':
CoreLib.cpp:14993:117: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
 (&((System_TypedReference__struct_data*) array)->Type)->m_value = (Void*) (((System_ByteAY*) (__this))->typeCode);
D:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0\libstdc++.a(eh_personality.o) multiple definition of __gxx_personality_sj0'
D:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/libstdc++.dll.a(d005771.o):(.text+0x0): first defined here
C:\Users\BRADUT~1.DIM\AppData\Local\Temp\ccMUz20I.o:CoreLib.cpp:(.text+0x24c7e5): undefined reference to
C:\Users\BRADUT~1.DIM\AppData\Local\Temp\ccMUz20I.o:CoreLib.cpp:(.text+0x24c7f8): undefined reference to _set_errno'
D:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../../mingw32/bin/ld.exe: C:\Users\BRADUT~1.DIM\AppData\Local\Temp\ccMUz20I.o: bad reloc address 0x7a8 in section
D:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation

Also, I tried the command line in "Long story short"
Il2c.exe /exe helloworld.cs /corelib:CoreLib.dll

-Apparently it worked fine:
Generating C file...Done.
Generating C file for CoreLib...Done
Compiling C file for CoreLib...Done.
Compiling C file...Done.
Compiling target exe. file...Done.

...but no helloworld.exe had been produced.

I then tried to add the /verbose parameter, but IL2C crashed everytime I did that:
D:\IL2C>Il2c.exe /exe helloworld.cs /corelib:CoreLib.dll /verbose
Generating C file...
Unhandled Exception: System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
at System.String.Format(IFormatProvider provider, String format, Object[] args)
at System.String.Format(String format, Object[] args)
at Il2Native.Logic.Il2Converter.ConvertTypeDefinition(ICodeWriter codeWriter, IType type, IEnumerable1 genericMethodSpecializatons, Boolean processGenericMethodsOnly, Boolean forwardDeclarations)
at Il2Native.Logic.Il2Converter.WriteTypeFullDeclaration(ICodeWriter codeWriter, IType type, IGenericContext genericContext, IEnumerable
1 genericMethodSpecializatons, Boolean processGenericMethods
at Il2Native.Logic.Il2Converter.ConvertTypeDeclaration(ICodeWriter codeWriter, IType type, IEnumerable1 genericMethodSpecializatons, Boolean processGenericMethodsOnly)
at Il2Native.Logic.Il2Converter.ConvertAllTypes(ICodeWriter codeWriter, IEnumerable
1 types, IDictionary2 genMethodSpec, ConvertingMode mode, Boolean processGenericMethodsOnly)
at Il2Native.Logic.Il2Converter.WritingDeclarations(IlReader ilReader, ICodeWriter codeHeaderWriter, IEnumerable
1 types, IDictionary`2 genericMethodSpecializationsSorted)
at Il2Native.Logic.Il2Converter.GenerateSource(IlReader ilReader, Settings settings)
at Il2Native.Logic.Il2Converter.GenerateC(IlReader ilReader, String fileName, String sourceFilePath, String pdbFilePath, String outputFolder, String[] args, String[] filter)
at Il2Native.Logic.Il2Converter.Convert(String[] sources, String outputFolder, String[] args, String[] filter)
at Il2Native.Program.Main(String[] args)

Could anyone please tell me what I am doing wrong?
Oct 2, 2015 at 11:01 AM
use official GCC MinGW port, link you can find on front page
Oct 3, 2015 at 2:50 AM
Edited Oct 3, 2015 at 2:51 AM
Hi Alex,

Thank you for your explanations.
Indeed, after I used the GCC library you indicated, I was able to generate the Hello World with the command
Il2c.exe /exe helloworld.cs /corelib:CoreLib.dll

I have it a try on a computer without .Net and it worked after I copied a few dlls in the same directory as the helloworld.exe file, namely:

I'm really happy with this achievement!

However, the issue at # 4 above still exists, only the error message has changed to:

helloworld.cpp:3345:7: warning: second argument of 'Int32 main(Int32, SByte**)'
Int32 main(Int32 count, SByte** parameters) {
CoreLib.cpp: In function 'Void Void_System_Array_InternalGetReferenceFVoidP__Int
CoreLib.cpp:14993:117: warning: cast to pointer from integer of different size [
 (&((System_TypedReference__struct_data*) array)->Type)->m_value = (Void*) ( 

Don't know if this is really an issue, since the short command worked fine.

Oct 3, 2015 at 9:45 AM
They are warnings not errors. You can ignore them.