drh / lcc

The lcc retargetable ANSI C compiler

Home Page:https://drh.github.io/lcc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Building on Windows

norswap opened this issue · comments

Building lcc on Windows is basically fubar. The instruction are way outdated.

  • The identifier outp in cpp\cpp.c clashes with the Windows function of the same name. Renaming it the something else makes the problem go away. (It is only used in the cpp folder, from memory this includes :cpp.h, cpp.c, macro.c, include.c and maybe some other I forgot).
  • libc.lib no longer ships with Visual Studio. It should be replaced with libcmt.lib in etc\win32.src, which is apparently the multi-threaded version.
  • The compile output is littered with "ignoring unknown option -MLd" warnings.
  • I made it up to here, but then the test (make ... test) described in the installation guide fails because the file limits.s is generated nearly empty. The triple test (make ... triple) hangs forever.

I have not really investigated, but might it not be easier to base the Windows version on MinGW, as it is much closer to how the install works on Unix ?

Also, it would be great to offer precompiled binaries. It might at least be a temporary solution until the build system is fixed.

FWIW, as an experiment I tried compiling lcc with my own compiler (Smaller C) for Widnows. After bumping up the sizes of the internal tables/arrays in Smaller C and massaging lcc's code to exclude the features currently unsupported by Smaller C, I got it to compile and seemingly work. What I did outside of Smaller C issues is roughly:

  • Compile lburg
  • Run lburg on src\*.md to produce architecture-specific .c files (in reality I just did it for mips.md and removed other architectures (alpha, sparc, x86*) from src\bind.c; I also stumbled upon the missing check() function, which I defined as empty, however that's most likely wrong as it should come from dagcheck.md)
  • Compile src\*.c

That was enough to make lcc compile tiny snippets of C code like the following into MIPS assembly:

int a = 4;
int inca(void) { return ++a; }

Not terribly hard.

The limits tests fails because the VC headers became too complex for LCC to handle. In this case, VAARGS for macros are present.

You cannot use any standard header anymore because of that, you should define standard functions and whatsover manually.

Plus, for VC2015 onwards, which uses the new Universal CRT, your ld on etc/win32.c should look something like:

char *ld[] = { "link", "-nologo",
        "", "-subsystem:console", "-entry:mainCRTStartup",
        "$2", "-OUT:$3", "$1", "/NODEFAULTLIB", LCCDIR "liblcc.lib", "oldnames.lib", "libcmt.lib", "legacy_stdio_definitions.lib", "libucrt.lib", "kernel32.lib", 0 };

Hope this helps anyone also trying to get this to build and work on Windows.