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

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.


转载于:https://my.oschina.net/zeroli/blog/507535

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值