Tag Archives: MinGW-w64

A Little Example of ELLCC Under Windows

As I mentioned previously, it is easy to use ELLCC to compile C and C++ programs under Windows. Now that the latest releases of ELLCC come with the MinGW-w64 header files and libraries, all you have to do is download and install a Windows binary release and you have a full C/C++ development environment including the clang/LLVM based ecc compiler, binutils, and GDB. The tool chain can target Windows as well as various Linux systems as a cross compiler. You can also run ELLCC under Linux to target Windows. In fact, the Windows release has been compiled under Linux.

Here is a simple example of compiling and debugging a simple “hello world” program using the Windows cmd shell:

                                                                            
Microsoft Windows [Version 6.3.9600]                                             
(c) 2013 Microsoft Corporation. All rights reserved.                             
                                                                                 
C:\Users\rich>cd \                                                               
                                                                                 
C:\>cd ellcc                                                                     
                                                                                 
C:\ellcc>bin/ecc examples\hello\main.c -g                                        
'bin' is not recognized as an internal or external command,                      
operable program or batch file.                                                  
                                                                                 
C:\ellcc>bin\ecc examples\hello\main.c -g                                        
                                                                                 
C:\ellcc>bin/ecc-gdb a.exe                                                       
'bin' is not recognized as an internal or external command,                      
operable program or batch file.                                                  
                                                                                 
C:\ellcc>bin\ecc-gdb a.exe                                                       
GNU gdb (GDB) 7.7                                                                
Copyright (C) 2014 Free Software Foundation, Inc.                                
License GPLv3+: GNU GPL version 3 or later     
This is free software: you are free to change and redistribute it.               
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"       
and "show warranty" for details.                                                 
This GDB was configured as "i386-mingw32".                                       
Type "show configuration" for configuration details.                             
For bug reporting instructions, please see:                                      
.                                         
Find the GDB manual and other documentation resources online at:                 
.                                
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.exe...done.
(gdb) break main
Breakpoint 1 at 0x401571: file examples\hello\main.c, line 5.
(gdb) run
Starting program: C:\ellcc\a.exe
[New Thread 2432.0xc38]
warning: Can not parse XML library list; XML support was disabled at compile tim
e

Breakpoint 1, main () at examples\hello\main.c:5
5           printf("hello world\n");
(gdb) list
1       #include <stdio.h>
2
3       int main()
4       {
5           printf("hello world\n");
6       }
(gdb) c
Continuing.
hello world
[Inferior 1 (process 2432) exited normally]
(gdb)

Since I’m a *nix guy I’m more comfortable with a shell, as you can see by my ‘/’ vs. ‘\’ fumbling above. Here is the same thing done using the MSYS command shell:


rich@VirtualWin8-64 MSYS ~
$ cd /c/ellcc

rich@VirtualWin8-64 MSYS /c/ellcc
$ bin/ecc examples/hello/main.c -g

rich@VirtualWin8-64 MSYS /c/ellcc
$ bin/ecc-gdb a.exe
GNU gdb (GDB) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.exe...done.
(gdb) break main
Breakpoint 1 at 0x401571: file examples/hello\main.c, line 5.
(gdb) run
Starting program: C:\ellcc\a.exe
[New Thread 1936.0x538]
warning: Can not parse XML library list; XML support was disabled at compile time

Breakpoint 1, main () at examples/hello\main.c:5
5           printf("hello world\n");
(gdb) c
Continuing.
hello world
[Inferior 1 (process 1936) exited normally]
(gdb)

Cool stuff.

Using Config Files to use ELLCC+MinGW to Cross Compile for Windows

ELLCC is based on clang/LLVM of course. Previously I mentioned that I was experimenting with YAML based config files for the compiler driver. When I made that post and subsequently, several people had objections to the approach because it potentially required reading a file each time the compiler is involked and that it would make the already complicated driver code even more complicated. It came up again today in the LLVM mailing list and it got me to thinking that maybe another real world example might help.

I used MinGW to cross compile ELLCC for Windows hosts. I started to wonder what an ELLCC config file might look like for using clang to cross compile for Windows instead. I came up with this as a first cut example:

# based_on `i386-ellcc-linux'
# based_on `ellcc-linux'
---
based_on:        ''
global:          
  static_default:  true
compiler:        
  options:         
    - -target i386-ellcc-win32
    # - -no-integrated-as
  c_include_dirs:  
    - /usr/lib64/gcc/i686-w64-mingw32/4.8.4/include
    - /usr/lib64/gcc/i686-w64-mingw32/4.8.4/include-fixed
    - /usr/i686-w64-mingw32/sys-root/mingw/include
  cxx_include_dirs: 
    - '$R/include/c++'
assembler:       
  exe: '/usr/lib64/gcc/i686-w64-mingw32/4.8.4/../../../../i686-w64-mingw32/bin/as'
  output:          
    - '-o $O'
linker:          
  exe: '/usr/libexec/gcc/i686-w64-mingw32/4.8.4/collect2'
  output:          
    - '-o $O'
  start:           
    #- -e _start
  opt_static:      
    - -Bstatic
  opt_rdynamic:    
    - -export-dynamic
  opt_dynamic:     
    - -Bdynamic
  opt_shared:      
    - -shared
  opt_notshared:   
    - -dynamic-linker /usr/libexec/ld.so
  opt_pthread:     
    - -pthread
  options:         
    - -m i386pe
  static_crt1: '/usr/i686-w64-mingw32/sys-root/mingw/lib/../lib/crt2.o'
  dynamic_crt1: '$R/lib/i386-linux-eng/Scrt1.o'
  crtbegin:    '/usr/lib64/gcc/i686-w64-mingw32/4.8.4/crtbegin.o'
  crtend:      '/usr/lib64/gcc/i686-w64-mingw32/4.8.4/crtend.o'
  library_paths:   
    - '-L/usr/lib64/gcc/i686-w64-mingw32/4.8.4'
    - '-L/usr/lib64/gcc/i686-w64-mingw32/4.8.4/../../../../i686-w64-mingw32/lib/../lib'
    - '-L/usr/i686-w64-mingw32/sys-root/mingw/lib/../lib'
    - '-L/usr/lib64/gcc/i686-w64-mingw32/4.8.4/../../../../i686-w64-mingw32/lib'
    - '-L/usr/i686-w64-mingw32/sys-root/mingw/lib'
  cxx_libraries:   
    - '-lc++'
    - -lm
  profile_libraries: 
    - -lprofile_rt
  c_libraries:     
    - '-lmingw32'
    - '-lgcc'
    - '-lgcc_eh'
    - '-lmoldname'
    - '-lmingwex'
    - '-lmsvcrt'
    - '-ladvapi32'
    - '-lshell32'
    - '-luser32'
    - '-lkernel32'
    - '-lmingw32'
    - '-lgcc'
    - '-lgcc_eh'
    - '-lmoldname'
    - '-lmingwex'
    - '-lmsvcrt'
...

I called it i386-w64-mingw32, and, Hey Presto! a Windows cross compiler on my Linux box.

[~] dev% cat main.c
#include <stdio.h>

int main()
{
    printf("hello world\n");
}
[~] dev% ~/ellcc/bin/ecc -target i386-w64-mingw32 main.c
[~] dev% ./a.exe 
fixme:winediag:start_process Wine-Compholio is a Wine testing version containing experimental patches.
fixme:winediag:start_process Please don't report bugs at winehq.org and use our issue tracker instead:
fixme:winediag:start_process https://github.com/compholio/wine-compholio/issues
hello world
[~] dev% file a.exe
a.exe: PE32 executable (console) Intel 80386, for MS Windows
[~] dev%