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 ...
- 11-06-2009 #1Just 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..
- 11-06-2009 #2
You might be able to get away with
#include <unistd.h>
and using read and writeMake mine Arch Linux
- 11-07-2009 #3
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.
- 11-08-2009 #4Linux Guru
- 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!


Reply With Quote
