Help on Gcc

From Asibot & HOAP3 & TEO Wiki
Revision as of 02:38, 8 November 2010 by Jgvictores (talk | contribs) (Created page with '== Wrapping a class == 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 the…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Wrapping a class

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

  1. 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

  1. 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.