Help on Gcc

From Asibot & HOAP3 & TEO Wiki
Jump to navigation Jump to search

Random low-level stuff somewhat related to gcc.

Wrapping a class (needed to compile Darwin2k on a 2010 kernel)

http://oss.sgi.com/projects/inventor/mail/info-inventor-dev/msg00512.html You need to compile your source with the gcc option:

   -Wl,--wrap,__ctype_b

then compile an object (.o) from the following source

   #include <ctype.h>
   extern "C" {
   __const unsigned short int **__wrap___ctype_b (void) {
     return __ctype_b_loc();
   }
   }

and link it in.

Creating a static/dynamic library

Build libfoo.a on libc6 2.2.5 from foo.c as follows:

% cat foo.c 
#include <ctype.h>
int foo(int c)
{
       return isdigit(c);
}
% cc -o foo.o -c foo.c
% ar ruv libfoo.a foo.o <----------important step.

and copy libfoo.a to libc6 2.3.1 environment. On libc6 2.3.1:

% cat bar.c
#include <stdio.h>
extern int foo(int c);
int
main(int argc, char *argv[])
{
       printf("%d\n", foo(*argv[1]));
       exit(0);
}
% cc -o bar bar.c libfoo.a

libfoo.a(foo.o)(.text+0xa): In function `foo':

undefined reference to `__ctype_b'

collect2: ld returned 1 exit status Of course, libfoo.a is rebuilt on libc6 2.3.1, there are no problem.