LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Glibc questions (https://www.linuxquestions.org/questions/linux-newbie-8/glibc-questions-780843/)

pmil 01-08-2010 08:27 AM

Glibc questions
 
Hi all,

AFAIK, in addition to implementing the standard C library, glibc provides wrappers for system calls, threading support, and basic application facilities.

So because of that, glibc that will be used on my target system should be built based on the kernel version running on my target, right?

Based on the above, I am trying to build a glibc version for my target machine's kernel. However, I don't know to to build a glibc library for a target system and also where on the target's filesystem should be put? In which location Linux will start looking for the libraries required for a program to run (should I create an /etc/ld.so.conf file)?

Thanks a lot for any help.

knudfl 01-08-2010 09:07 AM

Glibc alone will not do at all.

The important thing is gcc, which creates objects depending
on the glibc, which was used to build the gcc.

You will probably need a complete tool chain :
1) binutils ( includes the ld / linker files ).
2) gcc
3) glibc + some headers from the target kernel.

Location : /home/"user"/tools/ or /opt/tools/
or /usr/local/tools/ .. whatever you like.
  • Important : tell us, which host you have, like
  • Fedora 12, Ubuntu 9.10 etc. ( architecture ? )
  • And please specify the target, + its architecture.
  • Architecture can be x86, x86_64, arm, ppc, etc.
.....

David1357 01-08-2010 09:19 AM

Quote:

Originally Posted by pmil (Post 3818840)
...running on my target...

Is the target an embedded system? Is the target a desktop computer?

pmil 01-08-2010 11:21 AM

Thank you all for your interest.

My host is Ubunty 9.10 and my target is an Atom 330 (x86). The target machine is used as an embedded system. My host's kernel version is 2.6.31-14-generic and the host's glibc version is 2.10.1-0ubuntu15.

I am using the GCC provided by Ubuntu's "build-essesntial" package. The version of GCC is 4.4.1.

What I have understand is that I need to somehow install the glibc version which I used to compile my programs to the target's filesystem so that dynamic linking can be done. Can you advise me on how to do so?

Let's say that I have a hello world program like the following, which is dynamically linked:

Code:

#include <stdio.h>
int main() {
        printf("Hello world!\n");
        return 0;

By using ldd, I see the shared libraries needed for its execution:

Code:

        linux-gate.so.1 =>  (0x00723000)
        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00bd0000)
        /lib/ld-linux.so.2 (0x00b96000)

At run time, the program will search for the printf() routine. Where it will search for the required library? Will it search under the /lib/ folder of the file system? How and where should I put glibc on the target's filesystem in order to be able to do dynamic linking?

Thanks in advance.

David1357 01-08-2010 12:04 PM

Quote:

Originally Posted by pmil (Post 3819040)
...my target is an Atom 330 (x86). The target machine is used as an embedded system.

Does the target have an hard drive? Does it use a flash file system? How much space do you have on your file system?

Are you able to boot the target to a bash prompt?

pmil 01-08-2010 03:37 PM

Quote:

Originally Posted by David1357 (Post 3819106)
Does the target have an hard drive? Does it use a flash file system? How much space do you have on your file system?

Are you able to boot the target to a bash prompt?

No, my target doesn't have a hard drive and it uses an initrd as its main filesystem. It has 1GB of RAM and yes, I am able to boot the target to a bash prompt.

Thanks.

knudfl 01-09-2010 11:57 AM

'ls /lib/libc-2*'

.. will show which glibc you already have on the atom system.

Replacing it with another version :
Will most often break the system.

Glibc is the system. ( Together with the kernel.)
.....

pmil 01-09-2010 04:44 PM

Quote:

Originally Posted by knudfl (Post 3820319)
'ls /lib/libc-2*'

.. will show which glibc you already have on the atom system.

Replacing it with another version :
Will most often break the system.

Let me clarify this. My target's filesystem is empty (there is nothing under /lib). It only has the absolutely necessary things for having a running system. All I am asking is how can I put a glibc version on it. AFAIU, I need to put the same version which is used on the host for the compilation of the user applications which I am gonna use.

Thanks.

knudfl 01-10-2010 12:04 PM

Please define running ..

I guess, you have a few commands available.
Can you do the command 'ls' ?
Example from "tty Linux", a Linux OS, total 8 MB :
ldd /bin/ls
.. the reply is : libc.so.6 , which is glibc.

May be you have a ' libc-2.x.so in another location ?
Please try : ls -R / | grep libc-2*

EDIT : Or : ls -R / | grep libc*
.....

David1357 01-11-2010 09:14 AM

Quote:

Originally Posted by pmil (Post 3819408)
...I am able to boot the target to a bash prompt.

Then you should already have libc installed in the correct place:
Code:

[user@machine:~]:ldd $(which bash)
        linux-gate.so.1 =>  (0xb80a3000)
        libncurses.so.5 => /lib/libncurses.so.5 (0xb803d000)
        libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb8039000)
        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7eda000)
        /lib/ld-linux.so.2 (0xb8089000)

If you are using some form of embedded Linux (e.g. uClinux), then you will have to build your application against whichever version of libc you built into your image.

David1357 01-11-2010 09:19 AM

Quote:

Originally Posted by pmil (Post 3820577)
My target's filesystem is empty (there is nothing under /lib). It only has the absolutely necessary things for having a running system.

Did you statically compile your version of bash?
Are you using uClinux and busybox?

Quote:

Originally Posted by pmil (Post 3820577)
All I am asking is how can I put a glibc version on it. AFAIU, I need to put the same version which is used on the host for the compilation of the user applications which I am gonna use.

It may seem like you are asking a very simple question. The problem is that it is not a simple question. We need more information before we can help you.

How did you build the kernel on your target?

The answer to that question will tell us how to help you get the correct libc on your target.

pmil 01-13-2010 09:27 AM

Quote:

Originally Posted by David1357 (Post 3822470)
Did you statically compile your version of bash?
Are you using uClinux and busybox?

Yes, busybox is statically compiled (that's why it works!). I am not using uClinux, just a vanilla kernel.

Quote:

Originally Posted by David1357 (Post 3822470)
It may seem like you are asking a very simple question. The problem is that it is not a simple question. We need more information before we can help you.

How did you build the kernel on your target?

The answer to that question will tell us how to help you get the correct libc on your target.

Thank you very much for your interest! I've built the kernel using the host's gcc (and eventually host's glic version). So, if I am about to use the host's gcc and glibc to build applications, should I copy the /lib/ folder of the host to /lib/ of the target's filesystem to have support of dynamic linking with glibc?

I know it's not the smartest/best way of doing it but it will work at all?

Thanks!

David1357 01-13-2010 12:27 PM

Quote:

Originally Posted by pmil (Post 3825184)
Yes, busybox is statically compiled (that's why it works!).

I am just trying to get a picture of what you have and how it works.

Quote:

Originally Posted by pmil (Post 3825184)
I've built the kernel using the host's gcc (and eventually host's glic version).

ok. That is very useful information.

Quote:

Originally Posted by pmil (Post 3825184)
I know it's not the smartest/best way of doing it but will it work at all?

The only way to find out is to try it.


All times are GMT -5. The time now is 08:21 PM.