[Happy Coding] lcc 4.2 build on ubuntu(linux)

2558 ワード

This page explain how to build lcc 4.2 on ubuntu.
1. download source code
lcc 4.2 source code tarbar can be downloaded from https://github.com/drh/lcc
2. build source code on 32bit
untar that downloaded tarbar, and then cd that source code folder.
a) set environment BUILDDIR to ./bin, and then make directory for it
b) make lcc driver, and generate host.o file, by using below command
make HOSTFILE=./etc/linux.c lcc
c) make other applications and core library liblcc.a
make all
3. run test
a) write one simple test.c file, just print "hello world"
b) cd bin folder(bin folder will have all binaries there), and then follow below steps:
  • set environment LCCDIR=.
  • ./lcc test.c

  • More, you can refer to http://drh.github.io/lcc/current/doc/install.html
    Generally, you may meet problem in last step: ./lcc test.c, I think you need do code change in etc/linux.c as below:
    char *include[] = {"-I" LCCDIR "include", "-I" LCCDIR "gcc/include", "-I/usr/include",
      "-I/usr/lib/gcc/i686-linux-gnu/4.8/include",
      "-I/usr/include/i386-linux-gnu",
      0 };
    
    char *ld[] = {
    	/*  0 */ "/usr/bin/ld", "-m", "elf_i386", "-dynamic-linker",
    	/*  4 */ "/lib/ld-linux.so.2", "-o", "$3",
    	/*  7 */ "/usr/lib/i386-linux-gnu/crt1.o", "/usr/lib/i386-linux-gnu/crti.o",
    	/*  9 */ "/usr/lib/gcc/i686-linux-gnu/4.8/crtbegin.o", 
                     "$1", "$2",
    	/* 12 */ "-L" LCCDIR,
    	/* 13 */ "-llcc",
    	/* 14 */ "-L/usr/lib/gcc/i686-linux-gnu/4.8", "-lgcc", "-lc", "-lm",
    	/* 18 */ "",
    	/* 19 */ "/usr/lib/gcc/i686-linux-gnu/4.8/crtend.o", "/usr/lib/i386-linux-gnu/crtn.o",
    	0 };
    
    int option(char *arg) {
      	if (strncmp(arg, "-lccdir=", 8) == 0) {
    		cpp[0] = concat(&arg[8], "/cpp");
    		include[0] = concat("-I", concat(&arg[8], "/include"));
    		include[1] = concat("-I", concat(&arg[8], "/gcc/include"));
    		//ld[9]  = concat(&arg[8], "/crtbegin.o");
    		ld[12] = concat("-L", &arg[8]);
    		//ld[14] = concat("-L", concat(&arg[8], "/gcc"));
    		//ld[19] = concat(&arg[8], "/gcc/crtend.o");
    		com[0] = concat(&arg[8], "/rcc");

    And then rebuild it.