WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: C HelloWorld program running at boot-time  (Read 3647 times)

Offline erics

  • Newbie
  • *
  • Posts: 2
C HelloWorld program running at boot-time
« on: January 26, 2011, 07:08:28 AM »
Hello .
Having written and compiled  a C "hello World"-type  program under Ubuntu  I wonder howto run this and put the message on the screen  in TC  without user-intervention when TC boots ?
I suppose by reading the TC-docs  the C-binaru must be converted to .ce format , is it ?
Everything in this TC-world is miles away from the usual Linux-paths .
First encounter with TC is quite a shock , nothing seems to work as usual pe:  " ls -al /dev/disk/by-label " &  'mount'  !
"man mount " : does not help either ,but this was to be expected given the small size of the system .
Very intriging , want to explore more .
Thanks in advance for every hint with that C-executable .


 

Offline gutmensch

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 605
  • I can make it disappear, have no fear!
    • remembrance blog
Re: C HelloWorld program running at boot-time
« Reply #1 on: January 26, 2011, 08:21:04 AM »
Binaries compiled with gcc against e.g. glibc (the gnu standard c libary), which is shared by ubuntu and tinycore can run directly on each system (as long as there aren't any compatibility issues like different architecture, gcc profiles, etc.). There's no need for converting anything.

To what you are referring is the package format for extensions. Whereas ubuntu uses .deb and fedora uses .rpm, tinycore uses .tcz. Although there are differences in the type and technique of files (.tcz is squashfs, .rpm is compressed cpio archive, etc.), it's basically the same on distros to use it. When you want to use a .tcz on tinycore you "install" it with tce-load -i /path/to/file.tcz or with a -w switch to download it from the web.

What you can do is, make an own extension for your hello world program, you will need compiletc and squashfs-tools-4.x extensions (download with appbrowser or tce-load -wi):

Code: [Select]
$ mkdir -p myext/usr/local/bin
$ gcc -o myext/usr/local/bin/helloworld helloworld.c
$ sudo chown -R root:staff myext
$ sudo mksquashfs myext myext.tcz
$ md5sum myext.tcz > myext.tcz.md5.txt

Then copy myext.tcz and myext.tcz.md5.txt to your tce folder (that is a folder called tce on any mountable partition, e.g. /mnt/sda1/tce) into the folder optional and edit a file called onboot.lst with myext.tcz in a line. Example:

/mnt/sda1/tce/onboot.lst
/mnt/sda1/tce/optional/myext.tcz

Code: [Select]
$ cat /mnt/sda1/tce/onboot.lst
myext.tcz

If you added or recreated new partitions (USB key or whatever) then run on a terminal
Code: [Select]
$ sudo rebuildfstab
$ sudo mount /dev/sda1

Tinycore will use the tce folder on any drive automatically as long as the device is already connected when booting. If you use an USB drive for that, add to your bootcodes waitusb=6, so that there's time for tinycore to recognize the device and mount it.
If I seem unduly clear to you, you must have misunderstood what I said. (Alan Greenspan)

Offline erics

  • Newbie
  • *
  • Posts: 2
Re: C HelloWorld program running at boot-time
« Reply #2 on: January 26, 2011, 11:09:43 AM »
Thanks for the reply , things are somewhat clearer now .
Actually my program is a bit more complicated than the classical "hello world" by using C++ classes  and functions .
I suppose the best way will be using 'static' linking in the whole affair ?
Thanks again for the advice , now I have an idea how to start
Erics

Offline gutmensch

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 605
  • I can make it disappear, have no fear!
    • remembrance blog
Re: C HelloWorld program running at boot-time
« Reply #3 on: January 26, 2011, 11:18:42 AM »
You're welcome! Static linking depends on what you want to achieve - if you want to have a binary, which you can throw somewhere and use it and there's enough space then do it statically and maybe compress it with UPX. If you're going to run other programs as well and you want to make it as small as possible then think about dynamic linking. TC basically provides all libraries you have on other linux'es, you just have to install them and their dev headers. There's no reason why dynamic linking should fail when it works on Ubuntu e.g.
If I seem unduly clear to you, you must have misunderstood what I said. (Alan Greenspan)

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: C HelloWorld program running at boot-time
« Reply #4 on: January 26, 2011, 02:38:28 PM »
"man mount " : does not help either ,but this was to be expected given the small size of the system .

what about
Code: [Select]
mount --help
optionally

Code: [Select]
tce-load -iw man-pages.tcz man.tcz
Also many extensions have their own equivalent -doc.tcz package.

These days many users would have redundant bandwith, so it might not make sense to sacrifice RAM or storage space for what can be accessed online at any moment.
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Re: C HelloWorld program running at boot-time
« Reply #5 on: January 26, 2011, 05:01:57 PM »
If the compiled program is in your backup/restore files (someplace under /home/tc in a default setup), you don't need to create a .tgz.  But you can if you want.  ;)

Let's say you build your hello.c in the home directory (/home/tc) and now have a hello binary file there.  Can you run it from the command line?

   $ ./hello

If not, make sure the execution permission bits are set (using fluff or "chmod 755 hello").

Now if you want this to run automatically each time you boot TC, add a call to it in your /opt/bootlocal.sh file:

  $ editor /opt/bootlocal.sh
(edit the file to include the line:
 /home/tc/hello
)

or

   $ echo "/home/tc/hello" >> /opt/bootlocal.sh


Alternatively, if you want to have your program run each time a user opens a terminal, add the call to the .ashrc file instead of /opt/bootlocal.sh.
--
Mike Lockmoore