Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (3) </ [1] 2 3 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: C - TCC - example / small tutorial, a simple  program with graphic output< Next Oldest | Next Newest >
enthusi Offline





Group: Members
Posts: 57
Joined: Dec. 2003
Posted: Jan. 14 2004,02:10 QUOTE

Hi there :)
I just uploaded a small C/TCC - Tutorial for DSL.
I wrote a small program during christmas when I had nothing with me but my beloved DSL-CD  :)  Since I had no C-books or internetresources available I coded along and commented every line. I soon came to the thought that it might be quite useful for others to take a look at this easy program without the need of heavy c-background. I kept things very simple and commented almost every line in a textfile.
I was quite sceptical about TCC and wanted the good "old" GCC...
TCC may not suit for general source-compilation but it is astonishing powerful for own little projects.
Maybe someone's interessted - please feel free to comment on it. I will start a thread in HOW-TOs. And hopefully you can help me with
comments on how to improve it.
I think it would be nice to add stuff like this (ok, to be honest: please add THIS one :-) to DSL... It takes up almost no space and can add many many fun hours for the DSL-user...

Get it here:
http://allthegoodthings.tripod.com/damnsmalllinux
TCC - tut for DSL
or type:
Code Sample

wget http://allthegoodthings.tripod.com/damnsmalllinux/tcc_tuturial_v0.1.zip

and unzip it...

Good night now,
enthusi


--------------
silence tells me secretly...
...everything
-------------------------------------------------------------
DSL on
cf-frugal-install on 700Mhz P3, 320 MB ram
cf-frugal & usb for via epia 5000, 512 MB ram
Back to top
Profile PM ICQ 
DrWatt Offline





Group: Members
Posts: 91
Joined: Nov. 2003
Posted: Jan. 14 2004,14:37 QUOTE

Thanks enthusi. I had tried to run tcc also and got the same sorts of errors as reported. At the time, I didn't have the time to figure it out, but the secret was the missing line

#include "/usr/lib/tcc/include/tcclib.h"

For those who know a smattering of C this line replaces the usual #include statements, such as #include <stdio.h>. Apparently a lot of the usual header files in tcc are inluded in the tcclib.h file. There are several other header files to explore in the tcc library files.


The other secret to getting immediate output is the -run opion in the command. For example, in a "c" file called test.c you would type

tcc -run test.c

This assumes you don't want to use the run script you provided.

Here is my test.c traditional first "c" file:

#include "/usr/lib/tcc/include/tcclib.h"
main()
{
printf("Hello DSL world");
return 0;
}

A good thing to do is to backup the old "/usr/share/scite/cpp.properties" file (in case you want to use it to compile gcc files in the future) and modify it so that you can compile link and run in scite. The output will appear in a separate pane on the right. Very handy. Here are the mods to the file:

1. After the line that reads "cc=g++ -pedantic -Os -fno-exceptions -fvtable-thunks -c $(FileNameExt) -o $(FileName).o" add a line that reads:

"tcc=tcc -run $(FileNameExt)"

2. Change all the lines that read "command.compile.*.c=$(cc)" to

"command.compile.*.c=$(tcc)"

there are 4 such instances. Save it. You must make the changes to this library file as root or it won't let you save them.

Now, you can edit in scite and use the "Complie command under tools to test your programs. Very nifty indeed. Standard c files should work.
Back to top
Profile PM AOL 
DrWatt Offline





Group: Members
Posts: 91
Joined: Nov. 2003
Posted: Jan. 14 2004,14:43 QUOTE

A bit more explanation on the mods to scite. If you do them, any file you open with a ".c" extension will be assumed to be a tcc file. Scite will format and color code it as such and when you use the compile command in scite it will use scite to run and compile it.

There is some online documentaion for tcc at

http://fabrice.bellard.free.fr/tcc/

enjoy.
Back to top
Profile PM AOL 
DrWatt Offline





Group: Members
Posts: 91
Joined: Nov. 2003
Posted: Jan. 14 2004,16:41 QUOTE

enthusi -- my scite mod works well for simple c programs that need no input. I suspect that it could also be made to make and build, since there are scripts in scite for that as well.

I do not understand why the following will not compile and create an executable:

tcc -o test2 test.c

When i run that, I get the following errors:

tcc: undefined symbol '__libc_start.main'
tcc: undefined symbol 'printf'
tcc: undefined symbol 'scanf'

Obviously the libraries arent being linked.

Your command line in tccrun:

"tcc -o $1.run -lstdc++3-libc6.1-2-2.10.0 $1.c"

does work, and creates an executable. Could you please explain what each part of that line does?

Thanks.
Back to top
Profile PM AOL 
enthusi Offline





Group: Members
Posts: 57
Joined: Dec. 2003
Posted: Jan. 14 2004,16:53 QUOTE

Hi!
I can give it a try.

when yoiu include the tcclib.h the functions you need are only declared.
Take a look at tcclib.h and you see what I mean (if you didnt already know).
So all they give is te name of a function and its parameters and return-values.
NOT the code itself!
The code for several functions is stored in different LIBS.
if you use te root-function SQRT() for example you have to declare it with math.h AND you have to link the mathlib to your program.
TCC (or any other compiler) will take the actual code of SQRT out of that lib.
In this case it is called libm..blabla. and can be linked to your program with the -l switch and the name of the lib without the leading word "lib".
So:
'tcc mathprogram.c -lm -o mathprogram'.
Same with the standardlibrary!
It is called libstdc++3-libc6.1-2-2.10.0 (you will find it in /usr/lib I think)
you have to link it to your code with -l'namewithout leading 'lib''.
So it is:
"tcc -o $1.run -lstdc++3-libc6.1-2-2.10.0 $1.c"
the $1 just stands just for the first parameter gicen to the bash-script
"tccrun test" will then execute
"tcc -o test.run -lstdc++3-libc6.1-2-2.10.0 test.c"
So your test.c IS then linked to the stdc-lib.
I hope this helps a bit...
Its not easy to know that you have to link wit THAT lib I admit.
Strange enough it is hardly mentioned anywhere...

have fun
enthusi


--------------
silence tells me secretly...
...everything
-------------------------------------------------------------
DSL on
cf-frugal-install on 700Mhz P3, 320 MB ram
cf-frugal & usb for via epia 5000, 512 MB ram
Back to top
Profile PM ICQ 
12 replies since Jan. 14 2004,02:10 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (3) </ [1] 2 3 >/
reply to topic new topic new poll
Quick Reply: C - TCC - example / small tutorial

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code