WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: compile HelloWorld on ubuntu and have it run on Tiny Core  (Read 637 times)

Offline stephen@centtech.com

  • Newbie
  • *
  • Posts: 1
compile HelloWorld on ubuntu and have it run on Tiny Core
« on: February 19, 2012, 08:49:02 AM »
Hi,

I'm sorry to ask this question, but I haven't been able to find my answer on the forums.
Is there an easy way to compile a hello.c program on a Ubuntu 10.10 machine
and have it work on Tiny Core Linux.

In other words is there a cross compilier for Ubuntu.  Everything I seen so far
involves building executables on Tiny Core Linux itself.

Thanks,

Stephen

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 6953
Re: compile HelloWorld on ubuntu and have it run on Tiny Core
« Reply #1 on: February 19, 2012, 09:15:30 AM »
If you build on some other platform, you need to build it static to be sure it'll run.
The only barriers that can stop you are the ones you create yourself.

Online bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 3528
    • My Community Forum
Re: compile HelloWorld on ubuntu and have it run on Tiny Core
« Reply #2 on: February 19, 2012, 09:29:02 AM »
Why not compile on TC instead of Ubuntu?
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline MikeLockmoore

  • Sr. Member
  • ****
  • Posts: 490
  • Good software needn't be big!
Re: compile HelloWorld on ubuntu and have it run on Tiny Core
« Reply #3 on: February 21, 2012, 11:34:19 AM »
Compiling and building a non-static (in other words, a more normal) executable on another machine may work if the Linux kernal versions are fairly close and the shared libraries (GNU Standard C Library, e.g. libc.so) are at the same version level.  So, if things are fairly close, you should be able to take the executable from the Ubuntu machine and copy it onto the Tiny Core machine and run it.  Don't forget to set the execute permission (e.g. chmod 775 hello) on the Tiny Core machine.   ;)

Normal Non-Static build...
1) compile + link on Ubuntu: gcc -c hello.c -o hello
2) test local (on Ubuntu): chmod 775 hello; ./hello
3) transfer to the Tiny Core machine (details will vary a lot)
4) make it executable on the Tiny Core machine: chmod 775 hello
5) test: ./hello

Did it work?  Do you get run-time linking (shared object) errors?  If the kernel and/or library versions are too different between machines, the run-time linking (like linking to .DLLs in Windows) may not work properly.  Hello.c and other programs that only use Standard C Library stuff will generally be more compatible than programs that rely on additional libraries.

If you want to cross-develop because the Tiny Core target system is very resource-limited, it might be worthwhile to set up Tiny Core on your Ubuntu machine, or run Tiny Core from a USB stick on that Ubuntu machine.  Then you can have the compiletc.tcz extension with the comiler and any other tools you want and have the run-time environment be the same as the more limited machine.  That should make development fairly simple and enjoyable and make troubleshooting much easier, since most differences will already be eliminated.

Static linking should eliminate most other sources of problems, but can make your executable much larger.  See this for some suggestions http://stackoverflow.com/questions/725472/static-link-of-shared-library-function-in-gcc.