WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

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

Offline stephen@centtech.com

  • Newbie
  • *
  • Posts: 1
compile HelloWorld on ubuntu and have it run on Tiny Core
« on: February 19, 2012, 11: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: 11049
Re: compile HelloWorld on ubuntu and have it run on Tiny Core
« Reply #1 on: February 19, 2012, 12:15:30 PM »
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.

Offline bmarkus

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

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

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Re: compile HelloWorld on ubuntu and have it run on Tiny Core
« Reply #3 on: February 21, 2012, 02:34:19 PM »
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.

Offline Ahmad

  • Newbie
  • *
  • Posts: 4
Re: compile HelloWorld on ubuntu and have it run on Tiny Core
« Reply #4 on: January 17, 2014, 01:18:53 PM »
Sorry to revive an old discussion but my question is relevant.

I too have an application that I would like to run every time TC starts up. It works great for the 32 bit version of kernel & core.gz and I do pretty much what MikeLockmoore illustrated up there.

Now if I build the same application on a 64 bit machine & then try to incorporate it with the 64 bit kernel & core.gz, running the application once the kernel is up and running from the command line outputs the error:

-sh: hello: not found

Just FYI:
chmod for the hello binary is 755
ldd shows that all dependencies are resolved.
I combined the rootfs64 & modules64 from the distribution_files and then added my hello binary to /usr/bin before remastering the gz.

Even though my own application is complicated and depends on a lot of libraries for this experiment I just did a simple "hello world" printf binary.

Any idea on what I might be doing wrong or

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: compile HelloWorld on ubuntu and have it run on Tiny Core
« Reply #5 on: January 17, 2014, 06:43:13 PM »
-sh: hello: not found

Just FYI:
chmod for the hello binary is 755
[...]
added my hello binary to /usr/bin
Why?
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)