Find the answer to your Linux question:
Results 1 to 4 of 4
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 ...
  1. #1
    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..

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    You might be able to get away with

    #include <unistd.h>

    and using read and write
    Make mine Arch Linux

  3. #3
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    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.

  4. #4
    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
    8,961
    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.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...