Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Linux Programming & Scripting > Hello world program without libraries

Forgot Password?
 Linux Programming & Scripting   C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 2 Weeks Ago   #1 (permalink)
Just Joined!
 
Join Date: Nov 2009
Posts: 1
Hello world program without libraries

Hi,

This was an onsite interview question and I was baffled.

I was asked to write a Hello world program for linux.. That too
without using any libraries in the system. I think I have to use
system calls or something.. The code shud run using -nostdlib and
-nostartfiles option..

It would be great if someone could help..
rardin is offline  


Reply With Quote
Old 2 Weeks Ago   #2 (permalink)
Linux Enthusiast
 
Join Date: Dec 2007
Location: Canada, Prince Edward Island
Posts: 524
You might be able to get away with

#include <unistd.h>

and using read and write
__________________
Make mine Mandriva Linux
gerard4143 is offline   Reply With Quote
Old 2 Weeks Ago   #3 (permalink)
Linux Enthusiast
 
Join Date: Mar 2008
Posts: 602
Hi,

-nostdlib does imply -nostartfiles if I understand the gcc docs correctly.
I think the stuff from unistd.h does itself rely on runtime libraries, so I doubt that would count.

Most assembler for Linux sites start with a syscall-only helloworld example, this is where I'd go.
__________________
Debian GNU/Linux -- You know you want it.
GNU-Fan is offline   Reply With Quote
Old 2 Weeks Ago   #4 (permalink)
Linux Guru
 
Rubberman's Avatar
 
Join Date: Apr 2009
Location: I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
Posts: 2,662
Are you sure they didn't mean no shared libraries? You can create / link an executable such as hello_world with static libraries so that it can run on just about any system, even one with no shared libraries. All standard system calls at least use libc or libgcc which are by default shared libraries. However, if you specify the -static option when compiling the executable, it will link to the static libraries, resulting in a slightly bigger executable, but one that is not dependent upon any existing shared libraries or particular versions of shared libraries.
__________________
Sometimes, real fast is almost as good as real time.
Rubberman is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 03:45 PM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2