-1

For some reason, I'm trying to make a minimal Linux system which only has essential components to run. I succeeded in installing BusyBox on my system, but I am having trouble installing glibc on top of it.

I just followed the instructions on this site: http://wiki.beyondlogic.org/index.php?title=Cross_Compiling_BusyBox_for_ARM

As per the instructions, all the libraries produced by glibc were put in the '/lib' directory. But when I tried to execute a dummy C program as follows

#include <stdio.h>
int main { printf ("hello\n"); }

the system printed a "not found" message. Presumably this message means the system cannot find the glibc libraries.

How can I make the system find the libraries in the '/lib' directory by default? If the Linux kernel already finds libraries from there by default, what could have been wrong?


The above program was put in the '/scratch' directory with the name 'a.out'. I tried to execute it inside the directory by typing './a.out'. Here is the result of 'ls' in the root directory

bin  dev  etc  include  lib  linuxrc  proc  root sbin  scratch  sys  usr

As I mentioned, all the glibc libraries are in the '/lib' directory.

Gwangmu Lee
  • 437
  • 3
  • 12
  • What exact commands did you type? – Basile Starynkevitch Nov 12 '15 at 17:49
  • 1
    And what was the *exact unedited* system response? – n. m. could be an AI Nov 12 '15 at 17:50
  • Please **edit your question** to improve it (notably by giving the *exact* commands that you tried) – Basile Starynkevitch Nov 12 '15 at 17:58
  • The command was simply './a.out' in the directory where the above program (a.out) were. The unedited system also printed "not found" :( – Gwangmu Lee Nov 12 '15 at 18:01
  • @GwangmuLee How/where did you compile your example program ? Perhaps you're using a compiler toolchain that links to some other standard C library, and not glibc ? Also note that glibc needs a slew of other things as well, at the very least ld-linux.so.2 – nos Nov 12 '15 at 18:08
  • @nos Oh I got that. I compiled the example on my host system, so it might have been tried to link to some other libc library. It is not as easy as I expected to install libc on top of Linux kernel. Thanks anyway :) – Gwangmu Lee Nov 12 '15 at 18:21
  • Well, do a `readelf -a ./a.out | grep interpreter` and see what it says, is that file on your target ? – nos Nov 12 '15 at 18:25
  • [Requesting program interpreter: /lib/ld-linux.so.3] Actually I checked 'readelf -d a.out' but it didn't show 'ld-linux.so.3'. What's 'ld-linux.so.3' and how can I load it on my kernel? Any article I can refer would be great help for me. – Gwangmu Lee Nov 12 '15 at 18:29
  • Your edited question is still not precise enough. – Basile Starynkevitch Nov 12 '15 at 18:30
  • @BasileStarynkevitch Oops sorry :(. Actually because there are lots of things I could not understand, I had no idea what to write on my question. – Gwangmu Lee Nov 12 '15 at 18:34
  • You might see if this helps http://stackoverflow.com/questions/16935168/cross-compile-helloworld-for-arm – nos Nov 13 '15 at 19:30

1 Answers1

1

The not found message is certainly not due to lack of libc (what exact commands did you type to get that?). Perhaps you have some PATH issue, and your shell (probably BusyBox) gave you that? Try typing the entire path of your executable.... If ldd(1) or strace(1) are available, you might want to use them.

You apparently want to undertake something very similar to Linux From Scratch.

You might be interested in musl-libc (it is an alternative to GNU glibc, perhaps slightly easier to build)

Stricto sensu, you cannot have a running system with just a bare Linux kernel, it needs at least some initial program (e.g. /sbin/init, or /bin/sh, or whatever you give thru init= thru GRUB or some other loader to your kernel)

BTW, your issue is certainly not a kernel issue, it could be some dynamic linking one (e.g. related to ld.so(8) or whatever "interpreter" is mentioned in your ELF executable, see elf(5)). When the kernel fails to execve(2) some file, it won't output on stderr, is is giving error notice thru errno(3) (as specified by the ABI)

Use objdump(1) & readelf(1) (perhaps the cross-build variants of them) on your executable to understand what is inside it.

I recommend to read more about Linux programming before undertaking such a route.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • I tried to type the absolute path of 'a.out', but it didn't work out :(. For you information, the boot was successful on QEMU with '/sbin/init'. – Gwangmu Lee Nov 12 '15 at 18:10
  • Typically though, such a "not found" message is due to the lack of a dynamic linker, which would be typical if the program is compiled with a toolchain linking to another libc that isn't installed on the target, or the target is missing the dynamic linker that needs to match its libc. – nos Nov 12 '15 at 18:11
  • I also considered to refer Linux From Scratch, but I found it is too much for now to follow the entire instructions. Thanks for the recommendation :) – Gwangmu Lee Nov 12 '15 at 18:12