tcc scripts


Forum: Other Help Topics
Topic: tcc scripts
started by: clacker

Posted by clacker on Oct. 28 2004,00:44
I just learned that you can write shell scripts in C using the tcc C compiler included in dsl!  To compile a normal program, you would use tcc test.c to compile the following file

Code Sample

/* test.c */
#include <tcclib.h>

int main()
{
    printf("Hello, DSL\n");
    return 0;
}


To run it as a shell script, create the following as a file, save it as test, change it's mode with chmod 777 test, then run it by typing test.

Code Sample

#!/usr/bin/tcc -run
#include <tcclib.h>

int main()
{
    printf("Hello, DSL\n");
    return 0;
}


I see that they have an < article on SlashDot > about tcc and tccboot, which compiles the kernel at boot time!  Looks like tcc is moving up in the world of being small.

Posted by Dafydd Cealleigh on Oct. 28 2004,02:35
I thought 777 set the directory bit.
Posted by AwPhuch on Oct. 28 2004,04:01
no it can be used to set a file to read/write/execute

Brian
AwPhuch

Posted by SaidinUnleashed on Oct. 28 2004,04:14
cool. This might make it much easier to build Linux from scratch.

Might have to check it out during winter break.

-J.P.

Posted by clacker on Oct. 28 2004,13:04
Dafydd Cealleigh, it does set that bit.  I'm a lazy programmer, I see I could have used chmod +x test as well.

EDIT:

wrong, it doesn't set the directory bit.  I read up and then remembered (you tend to do things by route after a while instead of thinking):

1 = execute
2 = write
4 = read

add the numbers for the mode you want.  You need three numbers, one for user, the second for group, and the third for other.  So my bits were set for read, write, & execute for me, my group, and everyone.

Posted by ke4nt1 on Oct. 28 2004,15:11
Quote
EDIT:

wrong, it doesn't set the directory bit.  I read up and then remembered (you tend to do things by route after a while instead of thinking):

1 = execute
2 = write
4 = read

add the numbers for the mode you want.  You need three numbers, one for user, the second for group, and the third for other.  So my bits were set for read, write, & execute for me, my group, and everyone.


Correct!  
Good Work!
73
ke4nt

Posted by Lii on Nov. 27 2004,07:03
is there more to do before compiling?
I get the err:
tcc: undefined symbol '__libc_start_main'
tcc: undefined symbol 'printf'
thx

Posted by roberts on Nov. 27 2004,18:38
Lii, looks like you must be trying to create an executeable.
Just add the -lc option. That will link with the C library and you should get your result.

Posted by Lii on Dec. 02 2004,06:13
thx, roberts
you were perfectly right! :)

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.