1

I want to do some modifications to the glibc library. The first step is to be able to use a specific version when I compile a program. I'm under ubuntu 12.10 and my directories are :

/mydirectory/glibc-2.17 (where I have extracted the last version from the website)
/mydirectory/glibc-2.17-build (where I have executed the configure and make command)
/mydirectory/test/helloworld.c (where I have my helloworld program)

The helloworld.c is the following:

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
   char glibc[256] = "xxxx"; /* How to detect the glibc version here ? */
   printf("hello, world\n");
   printf("glibc version = %s\n", glibc);
   return 0;
}

First how can I print the version of glibc ? (I think that there is a macro/constant in glibc for that).

Second, what command line should I use to compile my helloworld.c file to use the glibc that is in /mydirectory/glibc-2.17-build ?

Vincent
  • 57,703
  • 61
  • 205
  • 388
  • The `-L` option to `ld` adds a directory to the library search list. – Barmar Apr 11 '13 at 11:15
  • Hmm... wouldn't using some other glibc than the system one result in problems once the executable links some *other* library (which in turn was linked against the system libc)? – DevSolar Apr 11 '13 at 11:22

1 Answers1

1

Use -L pathname to explicitly specify a pathname to ld as Barmar has said in the comment.
It's suggested to use static linking -static or there might be problems during execution I think.

Actually my own solution to this problem would be: compile and link the source code as normal, and invoke with LD_PRELOAD set to your specified version of shared objects.
See http://linux.die.net/man/8/ld.so

starrify
  • 14,307
  • 5
  • 33
  • 50